I need to embed a out-of-prcess COM execution in my C# application. The COM execution is written in C++/ATL. Sometimes my COM create process will not start, so I manage to use a timeout to interrupt it.
My COM object initializing process:
using MyCOM;
//...
private MyCOM.Mylib _com; // COM object
private void MyInitJob()
{
_com = new MyCOM.Mylib();
}
private bool Initial()
{
System.Threading.Thread mythread = new System.Threading.Thread(MyInitJob);
mythread.Start();
if (!mythread.Join(5000))
{
mythread.Abort();
return false;
}
else
{
return true;
}
}
The above code seems could not stop MyInitJob()
thread while timeout is reached, and Initial()
will hang forever when new a COM object is stuck.
Could I know why new
takes forever, and could I interrupt when it takes too long?