One Excel RTD session affect the other

Apr 20, 2015 at 8:31 PM
I am finding that one Excel RTD Session can affect the other. When I am running two sessions of the same RTD Server and then use copy and paste in one session, I see the second session stop until the copying and pasting is done. I understand why certain blocking events stop the RTD in its own session, but what can cause this cross-over? Does this mean I am using the same instance of the RTD in both?

C
Coordinator
Apr 20, 2015 at 8:49 PM
What do you mean by "session"?
Inside an Excel process, there will be one instance of the RTD Server COM object, shared by all workbooks in that process. How it works across processes might depend on whether the RTD Server is implemented by an out-of-process COM server.

Note that since Excel 2010, different Excel windows might be part of a single Excel process.

Is the RTD server one you wrote, or from a third party?

-Govert
Apr 20, 2015 at 9:07 PM
Hi Govert,

Thanks for responding so quickly. Craig and I are looking at the problem together. By session we definitely mean separate instances of Excel.

Our RTD Server is based on suggested Excel DNA practices. All we do in our C# code is derive from IRtdServer. Our initial problem started as a random crash of Excel 2010 SP 2 on Windows 7 and we traced it to what seemed to be accumulation of messages resulting from us calling DispatchSynchronizationContext.Post() function to ensure the execution of UpdateNotify on the original Excel thread. We "slowed down" frequency of UpdateNotify calls which seemed to improve the situation but not "cure" it.

We then found that this accumulation seems to start to happen when a different instance of Excel is started and some trivial Copy and Paste performed on this new Excel instance which also uses the same RTD calls.

The same code and sheet have been operating under Windows XP/Excel 2003 just fine.

We create a new instance of DispatchSynchronizationContext in ServeStart() thus ensuring it is "attached" to the right Excel thread.

Our assumption has been that the RTD Server is an instance local to Excel where it is launched (via ServerStart). We've certainly been able to debug it by attaching to Excel and we never did anything to enable any out-of-process sharing of a single RTD Server instance.

Thanks
Oleg
Coordinator
Apr 20, 2015 at 9:23 PM
Hi Oleg,

From what you explain, the RTD servers in different Excel processes won't interfere. Your assumption about the RTD server being local to the Excel process is correct.

The artifacts you see around copy and pasting might have a different source. Excel does suspend the processing of updates in some contexts (e.g. if you start editing a formula). Also, it can be tricky to know what Excel does in terms of dealing with window messages (which you are indirectly using with your DispatcherSynchronizationContext). See what happens when you just keep the mouse pressed down on a sheet.

Excel-DNA has a base class (ExcelRtdServer) that addresses both the cross-thread and throttling issues with UpdateNotify as well as possible. It's not likely ot relate directly to the problem you report here, but I'd highly recommend you move to using it over time. It should certainly simplify your implementation.

-Govert
Apr 21, 2015 at 2:00 AM
Thank You Govert. We did start with ExcelRTDServer class a few months ago when migrating from ManagedXLL. Something prevented us from using it and we settled just with deriving from IRtdServer. We'll try it again.

Would you recommend we move away from DispatcherSynchronizationContext.Post() while migration to ExcelRTDServer?

Oleg
Coordinator
Apr 21, 2015 at 10:39 AM
Hi Oleg,

To be clear, I don't think a change to ExcelRtdServer will address the 'interaction' between Excel processes that you ask about here.

In general it's a good idea to switch to ExcelRtdServer. You can get rid of DispatcherSynchronizationContext (internally ExcelRtdServer implements something similar) and you safely call Topic.SetValue(...) as often as you want, from any thread. Please let me know if you run into any problems when trying to use it.

Recent Excel-DNA source check-ins on GitHub (https://github.com/Excel-DNA/ExcelDna) have fixed some minor RTD-related issues, but have not been tested much. If you try it and run into anything funny, please let me know.

The best place for Excel-DNA support and general discussion is the Google group at: https://groups.google.com/forum/#!forum/exceldna

-Govert