Pregunta

We have developed a .Net component which works great for WinForms. This component is using a SynchronizationContext to raise events from the underlying threads marshalling to the UI thread (of course the component would get the WindowsFormsSynchronizationContext automatically and use it to post the events to UI thread of application).

Now we want to create a nt service re-using this component. Since windows service does not provide a SynchronizationContext automatically, I thought we could use AsyncOperationManager (and its SynchronizationContext) in order to marshal all the events fired in the underlying threads of this components to a single processor thread. Would this be a good approach?

In my tests I used the call to AsyncOperationManager.CreateOperation(null); from different threads to check the behavior of the posted async operations (one executing MyService.OnStart() method ... and another an internal processing thread which I run in my service). For my surprise the thread ID of the posted async operation was always the one executing the MyService.OnStart() method, so probably the SCM thread.

There is a lack of documentation on MSDN regarding this, but I thought the thread who calls AsyncOperationManager.CreateOperation would be the one which the async operations will be marshalled to.

Could anyone shed some light here? Also, would you see something wrong with my intention of using this AsyncOperationManager in windows service? What are the other ways?

¿Fue útil?

Solución

I created my own threading model consisting of a processor thread which picks up requests from other threads and then creates back responses.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top