How to switch between streams in c # .net to update the GUI?
-
I have a thread (not the main thread) that is working with treeView, so this is how I call the main thread to update the treeView
I read about delegates, invoke ... I can't figure it out without an example yet.
Something like this:
Working in a background thread ....
We switched to the main stream
{
treeView.items.add (item);
}
Working in a background thread ....C# Anonymous, Nov 29, 2019 -
Another option:
this.Invoke(new Action(() =>
{
// работа с treeView
}));Anonymous -
There may be several options. I remember it well like this:
this.Invoke((MethodInvoker) delegate {
//
});
I don't see any point in InvokeRequired. In specifying a specific control instead of this - too.Arabella Patrick -
You can use
SynchronizationContext
Example:
// Инициализируете в UI потоке
synchContext = AsyncOperationManager.SynchronizationContext;
// Затем из потоков
synchContext.Post(OnComplete, data);
// Где OnComplete уже будет выполняться в контексте UIAnonymous -
Don't throw pissing slippers on))
And apply only when you understand what you are doing
Control.CheckForIllegalCrossThreadCalls = False
Delilah Wilkins
4 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!