I have a VB6 app that processes for a very, very long time. Killing it directly is not feasible, so I would like to set some sort of flag in the VB6 app. If in my C# app I d
I wouldn't keep a reference open across process boundaries but you can certianly cache the Long hWnd of the process and call kill on it from within .Net.
Here is a pretty standard scheme for asynchronous background processing with VB6 clients and VB6 servers. (For instance it's in Dan Appleman's book and Microsoft's VB6 samples.) I think it should work for a C# client too.
This scheme means that the client doesn't actually need to be multi-threaded, since the calling thread doesn't block while "DoStuff" is happening. The tricky part is making sure that DoStuff raises the events at appropriate intervals - too long, and you can't quit when you want to: too short, and you are slowing down DoStuff unecessarily. Also, when DoStuff exits, it must unload the hidden form.
If DoStuff does actually manage to get all the stuff done before being aborted, you can raise a different event to tell the client that the job is finished.
When you create the ActiveX Object keep a reference stored in the application or the thread. COM will handle the marshaling across threads. With a reference in hand you can call a method on it and kill it. If you keep the reference in the thread then you will need to use the interprocess messaging mechanism of .NET to pass to the .NET thread that you want to set the kill flag on the ActiveX EXE.