Worker thread in COM object
-
Hi All, I'm interested in your thoughts about the following: I have created an ATL COM object with an interface that consists of the methods Run and Stop. From a client application I would like to be able to call the Run method which causes my COM object to start a long operation. However, the Run method should return immediately because i don't want any multithreading code in my client. The long operation can be stopped by calling the Stop method. Currently, I create a worker thread in my objects Run method and set a stop flag when the Stop method is called. The worker thread periodically checks this flag and exits if it is set. For this to work, my object is created in the MTA. However, I have the feeling this can be done much simpler. (Also, there are warnings everywhere about creating threads in COM objects) I have looked into Asynchronous method calls but this limits my application to Win2000 and does not work with IDispatch derived interfaces. Any other idea's, pointers, samples ? Thank you, Alwin! Alwin Beukers
-
Hi All, I'm interested in your thoughts about the following: I have created an ATL COM object with an interface that consists of the methods Run and Stop. From a client application I would like to be able to call the Run method which causes my COM object to start a long operation. However, the Run method should return immediately because i don't want any multithreading code in my client. The long operation can be stopped by calling the Stop method. Currently, I create a worker thread in my objects Run method and set a stop flag when the Stop method is called. The worker thread periodically checks this flag and exits if it is set. For this to work, my object is created in the MTA. However, I have the feeling this can be done much simpler. (Also, there are warnings everywhere about creating threads in COM objects) I have looked into Asynchronous method calls but this limits my application to Win2000 and does not work with IDispatch derived interfaces. Any other idea's, pointers, samples ? Thank you, Alwin! Alwin Beukers
I use that exact method, and it seems to work fine for me. The worker thread in the Run() method I mean. If there is a classier way of doing it, I'd like to know. :) J