|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SynchronizationContext - Purpose?Hi,
I'm trying to wrap my mind around the new SynchronizationContext class. I have an idea what it's for but would appreciate anyone clueing me in. My guess is that it's a kind of generalized version of the ISynchronizeInvoke interface. In other words, it's a way to allow you to marshal operations to various threads for synchronization purposes. Am I on the right track? Hello, Leslie!
LS> I'm trying to wrap my mind around the new SynchronizationContext class. LS> I have an idea what it's for but would appreciate anyone clueing me in. LS> My guess is that it's a kind of generalized version of the LS> ISynchronizeInvoke interface. In other words, it's a way to allow you LS> to marshal operations to various threads for synchronization purposes. " The .NET Framework 2.0 introduces the SynchronizationContext class to address this and related scenarios. You can think of SynchronizationContext as ISynchronizeInvoke on steroids, providing the same functionality but at a higher level of abstraction, allowing it to work with environments other than Windows Forms. SynchronizationContext provides two methods you'll use most frequently, Send and Post. Send corresponds to ISynchronizeInvoke.Invoke, while Post corresponds to ISynchronizeInvoke.BeginInvoke. The idea here is that from your library, you can retrieve the current SynchronizationContext from the SynchronizationContext.Current static property. You can then use its Post or Send method to marshal your invocation to the proper thread. " ( http://msdn.microsoft.com/msdnmag/issues/06/06/NETMatters/default.aspx ) So, there are environments that have to have the same functionality as is in WinForms. Since SynchronizationContext has virtual methods different environments override its method to suit their own purpose. For instance there are WindowsFormsSynchronizationContext, AspNetSynchronizationContext etc |
|||||||||||||||||||||||