Search code examples
c#excelrtdcom-server

Excel calls IRTD.ServerTerminate while there are still active RTD formulas in a sheet


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??


Solution

  • 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:

    • write 50K+ of your RTDs to a sheet
    • start firing updates at your RTD from it's source (the higher the data throughput, the more likely excel will capitulate and restart the com server)
    • set the Application.RTD.ThrottleInterval = 0// (update whenever possible)
    • when up and running, navigate frantically around the sheet using the keyboard shortcuts (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 call ServerStart() 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!