I'm trying to write a simple RTD server that displays the current Excel ThrottleInterval.
As such, I have a simple Timer object that keeps updating the topic every few seconds. Per some code I learned from another ExcelDNA post, the first step is calling "var app = ExcelDnaUtil.Application;". When I call this in a System.Threading.Timer, Excel hangs on shutdown, even if I Dispose() the Timer.
Can anyone advise either an alternate implementation, or some way to work around this?
Here's a minimal version of my code that causes the hang. I have traced it exactly to the ExcelDnaUtil.Application line. If I comment out everything in the Timer block but that line, it still hangs.
public ThrottleRTDServer()
{
_topics = new List<Topic>();
_timer = new Timer(delegate
{
var app = ExcelDnaUtil.Application; // this alone causes the hang
}, null, 0, 2000); // updates every 2 seconds
}
protected override void ServerTerminate()
{
Logger.Instance.Log.Debug("ThrottleRTDServer ServerTerminate");
_timer.Change(Timeout.Infinite, Timeout.Infinite);
_timer.Dispose();
}