I seem not to find how to get the SynchronizationContext
of a given Thread
:
Thread uiThread = UIConfiguration.UIThread;
SynchronizationContext context = uiThread.Huh?;
Why should I need that?
Because I need to post to the UIThread from different spots all across the front end application. So I defined a static property in a class called UIConfiguration
. I set this property in the Program.Main
method:
UIConfiguration.UIThread = Thread.CurrentThread;
In that very moment I can be sure I have the right thread, however I cannot set a static property like
UIConfiguration.SynchronizationContext = SynchronizationContext.Current
because the WinForms implementation of that class has not yet been installed. Since each thread has it's own SynchronizationContext, it must be possible to retrieve it from a given Thread
object, or am I completely wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…