RTD updatevalue on worker thread

61 views
Skip to first unread message

Ashutosh Bhardwaj

unread,
Jul 5, 2024, 6:45:40 PMJul 5
to Excel-DNA
Hi, 

I have a question about RTD threading.

So, let's say I have a RTD server that starts like below on main thread 

 public class DemoRtdServer : ExcelRtdServer
 {
     protected override bool ServerStart()
     {


Now, I update the value on a worker thread (timer, non-blocking collection etc)  like, 
topic.UpdateValue(objValue);

Is there something inbuilt under the hood that will ensure/ synchronize that the update only happens on main thread or the thread that started the server? 

Or do I need to manually synchronize? 

Many Thanks,
Ashutosh

Govert van Drimmelen

unread,
Jul 9, 2024, 11:22:12 PM (12 days ago) Jul 9
to exce...@googlegroups.com

Yes, the ExcelRtdServer base class in Excel-DNA implements a mechanism that ensures cross-thread UpdateValue calls are safe and reliable. The implementation is quite complicated and has evolved over time, but I know of no current problems.

-Govert


--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/630e19b2-5d25-4df6-972f-116405959d46n%40googlegroups.com.

Ashutosh Bhardwaj

unread,
Jul 10, 2024, 8:24:29 PM (11 days ago) Jul 10
to Excel-DNA
Hi Govert, 

Thaks for the reply. I recently started to run into a new bug where, rtd is randomly returning ExcelEmpty. 

  1. I store the results in a Dictionary<string, objec[,]> , here the key is GUID.ToString()
  2. Then update the value with topic.UpdateValue(key) which is guid string. 
  3. Check that its a valid non-empty guid string, right before calling updatevalue. Its always a   non-empty guid string. 
  4. But, object result= XlCall.RTD  returns ExcelEmpty.
happens intermittently. 

Any suggestions? 


Thanks,
Ashutosh

Govert van Drimmelen

unread,
Jul 11, 2024, 3:36:14 PM (11 days ago) Jul 11
to Excel-DNA
I'm not sure I understand the interaction between the UpdateValue calls and the dictionary you keep.
The callback from Excel that runs the wrapper UDF does not happen synchronously with the UpdateValue call (and runs on the main thread, which might not be the one calling UpdateValue).
It does not sound like something that is a bug in the ExcelRtdServer mechanism, though that code and the interaction with Excel is complicated, so might be going wrong.

It would be useful to try to make a small project that reproduces the issue.

-Govert

Reply all
Reply to author
Forward
0 new messages