I’m in a basic C# .NET 4.0 WinForms application.
What i want to do is to write some logic to display a progress bar on the GUI thread while executing background operations on a background thread.
Android has implemented AsyncTask class which has some methods that need override: onPreExecute, doInBackground, onProgressUpdate and onPostExecute. OnPreExecute you can show the progress bar and on PostExecute (when the doInBackground method returns) you can hide it.
I read here that .NET 4.5 comes with something similar built in. Is there anything similiar in .NET 4.0?
If not, is it a good idea to implement something like android’s AsyncTask or is there a more conventional way to do this in C#?
Regards,
Dan
Closest thing in .NET would be the
BackgroundWorkerclass, using these events:DoWork– Occurs whenRunWorkerAsyncis called.ProgressChanged– Occurs whenReportProgressis called.RunWorkerCompleted– Occurs when the background operation has completed, has been canceled, or has raised an exception.