I'm not sure exactly what you mean, but what I need to do is for the
GUI or the console app to send an message event to the worker thread's
message loop and then invoke a function on the C++ in that message
handler. I can't use a queue because I also need the same thread to
process the window messages. Unless there is a way to wait for window
messages and queue input? Maybe some sample code will make it
clearer...
static void Main(string[] args)
{
MyObject obj = new MyObject ();
obj.Start();
obj.CallSomeCppFunction(); // see below for problem with this - I
bascially need to have this be sent as a window message to the
background thread (kind of like custom messages in Win32?) so that it
goes through the window message loop and end up calling
CallSomeCppFunction instead of it being called directly.
}
------------------------------- MyObject definition
Start()
{
[spawns off a new thread starting at thrdStrt]
}
thrdStrt()
{
COMObject cpp = new COMObject();
cpp.StartProcessing(); // this starts the c++ object which when
processing posts events back to this thread - let's just say for
example OnUpdateStatus(..)
Application.Run();
}
OnUpdateStatus() { [do some processing] }
CallSomeCppFunction()
{
cpp.DoSomeOtherWork(); // this will fail because all process on the
cpp object needs to be by the thread that created it.
}
Marc Gravell wrote:
Well, what do you want to do? If you just want a cancel flag, then a
sync-locked flag (or possibly just a volatile field) might do the job.
With BackgroundWorker you can detect cancel requests too. If you have
something more complex, perhaps something simple like a sync-locked
queue (checked periodically by the background thread, or woken via
Monitor.Pulse) might do the trick.
So what do you want to do?
Marc