How to use a BackgroundWorker?

How does .net backgroundworker work?

  • I import data from files in my application built in C#. If the files are not available, it sends out data import failure email. Instead I want to check if the files available 3 times and send failure email on 3rd time. I know one way is to use Backgroundworker but I'm not sure how. Any help is highly appreciated..

  • Answer:

    This MSDN article describes in detail how to use BackgroundWorker: http://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx Attach all computationally heavy functions to DoWork event. Call RunWorkerASync() to trigger the DoWork event. If you want to update UI or write to log file after the task is done, do so through functions attached to RunWorkerCompleted event. If you do so outside the BW implemetation, that will happen as soon as RunWorkerASync() is called as BW runs in parallel thread. Make sure to detach all event handlers as attaching multiple times would make backgroundworker do the task multiple times

Prateek Shrivastava at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.