I have a multi-threaded application using .NET 4.0. Sometimes this COM application referenced freaks out and just stop.
I want to know how to check for to see if this process is currently running within the questioned thread.
Example:
Exert from the main application:
ThreadedApp app = new ThreadedApp();
System.Threading.Thread thread = new System.Threading.Thread(x => app.Start());
thread.Start();
Business Object exert:
class ThreadApp
{
public void Start()
{
COMobject app = new COMobject(); // <- COM interop that starts up the COM app
foreach (var item in items)
{
new ThreadProcess().Process(ref app, item);
}
}
}
class ThreadProcess
{
public void Process(ref COMobject app, SomeItem item)
{
if (app == IVE_DIED_AND_I_DONT_KNOW_WHY) // How do I check this?
{
app = new COMobject();
}
// Process stuff
}
}
The main app can spin off N number of threads and therefore can spin off N number of the COMobject application. If you watch the Task Manager, you would see the COMobject.exe listed for each thread running.
I am trying to get away from try/catch blocks to increase performance but don't know how to check the state of the COM app from the calling thread.
Hope this makes sense and TIA.