I'm writing a component that would be used in WinForms or WPF applications also could be used in Windows services or Unit tests. Is there a way to use SynchronizationContext component in non UI apps?
+1
A:
Any (host) application can make its own SynchronizationContext
class and call SynchronizationContext.SetSynchronizationContext
.
Alternatively, you could make a no-op SynchronizationContext
in your library, then use it whenever SynchronizationContext.Current
is null
.
The question talks about writing a custom SynchronizationContext.
SLaks
2010-07-30 08:50:40
Do you know any examples?
Al Bundy
2010-07-30 08:52:25
Examples of what?
SLaks
2010-07-30 08:54:17
Of how "application can make its own SynchronizationContext", i.e. application wihtout UI loop, like Windows service.
Al Bundy
2010-07-30 08:57:41
If you need the callbacks to execute on a single thread, you'll need to make a thread-safe queue of pending callbacks and an infinite loop on the callback thread that executes the first callback on the queue.
SLaks
2010-07-30 09:21:41