Add-in Express event fired- issue when opening multiple documents at sane time (Quickly) - Add-in Express for Office and .NET

Add-in Express™ Support Service
That's what is more important than anything else

Add-in Express event fired- issue when opening multiple documents at sane time (Quickly) - Add-in Express for Office and .NET
Add-in Express event fired- issue when opening multiple documents at sane time (Quickly) - Add-in Express for Office and .NET 
Subscribe
Andrei Smolin


Add-in Express team


Posts: 14374
Joined: 2006-05-11
Hello Raj,

That is, you say that in Office 2013 (what exact build?) you reproduce WindowActivate events firing in an incorrect order; do I understand you correctly?

Jeff Gavin writes:
Could please check by executing 1 OR 2 sec time delay on office event's


Sorry? I don't understand what you need me to test? How do I "check by executing 1 OR 2 sec time delay"?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Jan, 2018 03:33:52 Top
Jeff Gavin




Posts: 14
Joined: 2016-11-09
Office Build 15.0.4569.1504. Yes, the last WindowActivate event is fired different from Active workbook to the user.

We are getting data from the database and loading them in office ribbon controls in these events. it will take 2 sec to do these. To reproduce this you may need to doo thread.spleep(2Sec).

FYI, due to wrong WindowActivate event fired, the current state is maintained with the wrong workbook properties. So while saving this file is replacing a wrong database record. Could you please suggest any other event, where I can load data from the database during the workbook active to the user.

Thanks
Raj
Posted 13 Jan, 2018 03:07:28 Top
Andrei Smolin


Add-in Express team


Posts: 14374
Joined: 2006-05-11
Hello Raj,

Jeff Gavin writes:
To reproduce this you may need to doo thread.spleep(2Sec).


In what event?

Please note, I explained this already, we won't be able to do anything about the order of events: Add-in Express just retranslates the events that the host application raises.

I suggest that you don't wait for 2 seconds; this is too long.

First off, at the design time, you should populate the Ribbon with placeholder controls; make all or most of them invisible. Second, read the database in another thread. When all the data are read, call the ADXAddinModule.SendMessage() passing it an integer >= 1024; find details in section Wait a Little at https://www.add-in-express.com/docs/net-office-tips.php#wait-a-little. Sending this message causes the OnSendMessage event of the add-in module. There are *many* messages that causes that event to occur; filter out your message. When you receive it, use the information you've read from the DB to change the properties (caption, enabled, visible, etc.) of the pre-created Ribbon controls.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 15 Jan, 2018 03:53:22 Top
Jeff Gavin




Posts: 14
Joined: 2016-11-09
Hello Andrei,

We Have these Database Calls on adxExcelEvents_WorkbookOpen and adxExcelEvents_WorkbookActivate active events. We have some business logic on adxExcelEvents_WorkbookDeactivate event also.

Thanks for the suggestion, I will look into it.

Thanks
Raj
Posted 16 Jan, 2018 03:09:03 Top
Andrei Smolin


Add-in Express team


Posts: 14374
Joined: 2006-05-11
Hello Raj,

If you have a sample project demonstrating how using Thread.Sleep() creates this issue, please send it to the support email address; find it in {Add-in Express installation folder}\readme.txt; please make sure your email contains a link to this topic.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 Jan, 2018 04:29:47 Top
Jeff Gavin




Posts: 14
Joined: 2016-11-09
Hello Andrei,

I mean to say, implement some logic on workbook active event which takes some time in the main thread.

Out current system is processing Document initialization which contains ( Getting attributes from a file, attribute from Database, validating attributes, Handle Conflict Resolution Quietly) in adxExcelEvents_WorkbookOpen event.

add-in express events are executing in the correct order with the below solution

Solution:

1) Need to execute this process in another thread. (Need to wait for completion. reason --3 step)
2) Use ADXAddinModule ADXAddinModule.SendMessage() event to process any UI updates

3) We have an issue with 1st step, As this Document initialization is on adxExcelEvents_WorkbookOpen, upcoming events adxExcelEvents_WorkbookActivate, adxExcelEvents_WorkbookDeactivate need the doc initialization information. We need to wait until thread process complete in adxExcelEvents_WorkbookOpen event.

Do you have any suggestions for this?

Thanks
Raj
Posted 17 Jan, 2018 01:40:10 Top
Andrei Smolin


Add-in Express team


Posts: 14374
Joined: 2006-05-11
Raj,

I've created an add-in that calls Tread.Sleep(2000) in the WorkbookActivate event. I can't reproduce the issue using these Excel versions:
- 16.0.8827.2131 64bit
- 16.0.8911.2016 32bit
- 15.0.4963.1002 64bit

If you have a sample project demonstrating how using Thread.Sleep() creates this issue, please send it to the support email address; find it in {Add-in Express installation folder}\readme.txt; please make sure your email contains a link to this topic.

Jeff Gavin writes:
We need to wait until thread process complete in adxExcelEvents_WorkbookOpen event.


Is it possible to apply the information that that thread produces after it completes instead of using it in WorkbookActivate? I can imagine the thread produces the required state of some Ribbon control after long calculations; in this case, you could hide/disable that control waiting for the calculations to complete and set the required control state later, when the process is completed.

As to WorkbookDeactivate, if it is followed by WorkbookActivate, you can use WorkbookActivate to do the things you do in WorkbookDeactivate.

Another approach. Lets imagine you block all the ways for the user to open a document except for clicking a control that you provide. Clicking the control opens a FileOpen dialog controlled by you. When the user chooses a file to open, you retrieve file attributes, use Open XML to retrieve workbook attributes, process the attributes and call Workbooks.Open to open the workbook when the job is done.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Jan, 2018 07:02:24 Top