Quantcast
Channel: Accessing UI controls in Task.Run with async/await on WinForms - Stack Overflow
Browsing latest articles
Browse All 7 View Live

Answer by codebased for Accessing UI controls in Task.Run with async/await on...

I am going to give you my latest answer that I have given for async understanding.The solution is as you know that when you are calling async method you need to run as a task.Here is a quick console...

View Article



Answer by Metro for Accessing UI controls in Task.Run with async/await on...

Try this:replacelabel1.Text = "test";withSetLabel1Text("test");and add the following to your class:private void SetLabel1Text(string text){ if (InvokeRequired) {...

View Article

Answer by svick for Accessing UI controls in Task.Run with async/await on...

When you use Task.Run(), you're saing that you don't want the code to run on the current context, so that's exactly what happens.But there is no need to use Task.Run() in your code. Correctly written...

View Article

Answer by Sriram Sakthivel for Accessing UI controls in Task.Run with...

Try thisprivate async Task Run(){ await Task.Run(async () => { await File.AppendText("temp.dat").WriteAsync("a"); }); label1.Text = "test";}Or private async Task Run(){ await...

View Article

Answer by Persi for Accessing UI controls in Task.Run with async/await on...

Why do you use Task.Run? that start a new worker thread (cpu bound), and it causes your problem.you should probably just do that: private async Task Run() { await...

View Article


Answer by Gerrie Schenck for Accessing UI controls in Task.Run with...

Because it's on a different thread and cross-thread calls aren't allowed.You will need to pass on the "context" to the thread you are starting. See an example here:...

View Article

Accessing UI controls in Task.Run with async/await on WinForms

I have the following code in a WinForms application with one button and one label:using System;using System.IO;using System.Threading.Tasks;using System.Windows.Forms;namespace...

View Article
Browsing latest articles
Browse All 7 View Live




Latest Images