1

I have WaitDialog with Marquee style ProgressBar.

  1. Is this a proper way to display it ?

     var wd = new WaitDialog(); Task.Factory.StartNew(() => { LongRunningMethod(); wd.Close(); }); wd.ShowDialog(); 
  2. Please recommend a proper way to report progress from a Task for non Marquee ProgressBar.

1
  • You may find this post useful. Commented Aug 23, 2016 at 15:45

1 Answer 1

5

What I think you're looking for is a way to run your long running method and display a progress dialog without locking up the UI. You also need to watch out for cross-threading issues by accessing your UI from a different thread.

What I would suggest is to pattern it this way which will keep your application responsive while the task is running:

 var wd = new WaitDialog(); wd.Show(); // Show() instead of ShowDialog() to avoid blocking var task = Task.Factory.StartNew(() => LongRunningMethod()); // use .ContinueWith to avoid blocking task.ContinueWith(result => wd.Invoke((Action)(() => wd.Close()))); 

You show your progress dialog -- whether it has a marquee or not is of no consequence -- and then you spin up your LongRunningMethod on its own task. Use the .ContinueWith method to close your dialog when the task has completed and to also avoid blocking the rest of your program.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.