synchronizationcontext

.NET SynchronizationContext - Which thread does it Send/Post to?

I'm planning on using the SynchronizationContext class to perform some cross-thread marshalling of UI updates. The idea is to avoid having to have a reference to the main form (i.e. the one in Application.Run(form)) just so I can say mainForm.BeginInvoke(); However, one thing that isn't clear from the documentation, is that when you ca...

Multithreaded message pumping without second form

I have a C# application which uses a COM component. This COM component require a message pump (Application.Run()) to do its processing. This means it's been stuck on the main thread. But I recently discovered that it's possible to start another Application.Run on another thread which gets its own ApplicationContext. So I want to host...

Exception practices when creating a SynchronizationContext?

I'm creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I'm wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used to Send (execute synchronously) or Post (execute asynchronously) delegates of type SendOrPostCallback. Although in both cases I invoke the ...

Using SynchronizationContext for sending events back to the UI for WinForms or WPF.

I'm using a SynchronizationContext to marshal events back to the UI thread from my DLL that does a lot of multi-threaded background tasks. I know the singleton pattern isn't a favorite, but I'm using it for now to store a reference of the UI's SynchronizationContext when you create foo's parent object. public class Foo { public event ...

What is the difference between SynchronizationContext.Send and SynchronizationContext.Post?

Thanks to Jeremy Miller's good work in Functional Programming For Everyday .NET Development, I have a working command executor that does everything I want it to (do heavy lifting on the thread pool, send results or errors back to the synchronization context, and even post progress back to the synchronization context), but I can't explain...

Alternative of Dispatcher class (from .net 3.0) to use in .net 2.0 context

Hi guys, I need an alternative for Dispatcher (.net 3.0) to use for a windows service (done in .net 2.0). Can you give me some idea how to achieve something like that or point me some links? I know that a dispatcher has a SynchronizationContext behind, but I don't know how I can use a SynchronizationContext into a service. If you thin...

Why SynchronizationContext does not work properly?

I have following code: [TestMethod] public void StartWorkInFirstThread() { if (SynchronizationContext.Current == null) SynchronizationContext.SetSynchronizationContext( new SynchronizationContext()); var syncContext = SynchronizationContext.Current; Console.WriteLine("Start work in the first thread ({0}...