0

I have written a c# RTD server based off of Kenny Ker's Multiple Topics in C#

The main difference between his design and mine is that my data comes from a WCF client. I use the same type of timer and every couple of seconds I call m_callback.UpdateNotify();. My RefreshData method calls a function in my WCF client with the topic values and uses the result as the value for excel. It all works excellent.

The problem comes when I close excel.

When I close Excel I get a message box that says "Microft Excel has stopped working"

My ServerTerminate() method clears all of my topics, calls close on my WCF client and exits without error.

I thought the problem might be a COM issue so I have tried adding

while ( Marshal.ReleaseComObject( m_callback ) > 0 ) ;
m_callback = null;

The pop up still showed up so I tried adding

GC.Collect();
GC.WaitForPendingFinalizers(); //SEHException thrown from this
GC.Collect();
GC.WaitForPendingFinalizers();

Adding these lines does throw an exception. if I ignore the exception excel closes without any problems, but if I install my RTD server on a computer with excel 2010, then the pop up box is still there.

I have Excel 2007 (12.0.6665.5003) SP3 MSO (12.0.6662.5000) I am developing my c# RTD Server using Visual Studio 2008 and my project has a reference to Microsoft.Office.Interop.Excel version 12.0.0.0

MarkB42
  • 725
  • 9
  • 23
  • Could you elaborate more on how you made it work when removed the Excel assembly, please. I've tried copying exactly the same interfaces, same GUID's, keeping TypeLibType and DispId ids with no luck. Also combining these interfaces with MarshalAs parameters as suggested per [Kenny Ker](http://weblogs.asp.net/kennykerr/archive/2008/12/16/Rtd7.aspx). It works just at the beginning though, when it connects to ConnectData() because I see data, but after it starts refreshing, got an N/A, and after that, never see any data at all. Is there any possibility if you paste the interfaces here or send the – Victor E Feb 13 '14 at 20:33
  • I had to use the Object Browser on the interop assemblies to get it right. But [here](https://gist.github.com/buchmoyerm/9001271) is the file I used. However, I have since switched to using ExcelDna and I highly recommend it. – MarkB42 Feb 14 '14 at 13:51

1 Answers1

0

The question was fairly vague, but that's because I really had no idea where to start. Every thing seemed to be working correctly.

After playing around with the code I noticed that I had an object that implemented IDisposable that I called Dispose on when I was done with it. The object also had a finalizer that called Dispose. I changed it to be more like this with a protected Dispose(bool).

I also removed the Excel assembly per Kenny Ker again (however just copying his code didn't work. I actually copied the interfaces straight from the excel interop assembly).

After doing that I was able to get rid of the lines I added (for marshalling the garbage collecting) above and excel now closes without a problem.

MarkB42
  • 725
  • 9
  • 23