I have a C# RtdServer
that receives data updates from a TCPListener
. It's runs as expected except for that at certain points when it still has active RTD()
s in the sheet ServerTerminate()
is called and I can't seem to figure out why.
I was of the understanding that ServerTerminate()
is called if:
- All rtd formulae are deleted
ServerStart()
doesn't return 1
What other reasons are there for excel to call ServerTerminate()
?
EDIT:
Here is how I setup the HeartBeat
mechanism:
public int ServerStart(IRTDUpdateEvent callback)
{
callback.HeartbeatInterval = 60000; // 1 min HB
_callback = callback;
// Other setup ...
return 1;
}
This is the HeartBeat
code
public int Heartbeat()
{
_log.Info("HB called...");
return 1;
}
From above, I expect to see calls to HeartBeat
every 60 seconds (60Kms) but I see no logging of this. I'm stumped - any ideas??
After some time I found that excel will restart a com server (rtd) if the UI thread is heavily under strain.
I was able to reproduce this 'server restart' by aggressively using the keyboard shortcuts:
shift+▲▼◀▼
to navigate in a sheet that is heavily loaded with active RTDs. Although this isn't a reliable method of forcing excel to restart the server it works often enough to test. You can try to reproduce the com server restart by doing the following:Application.RTD.ThrottleInterval = 0//
(update whenever possible)shift+▲▼◀▼
)This will likely cause excel to restart the RTD and in doing so, first call
ServerTerminate()
(regardless of how many RTDs exist in the sheet) and then callServerStart()
effectively restarting the server which explains the behavior noted.The server restart resets all of the data in your RTD implementation so you should consider this as a complete reset so any subscriptions should be reset also.
Hth!