BackgroundWorker in VS .Net 2005
Posted on 2006-06-04
I'm programming a big program in C#
I want to write a small task in my program like this:
My user select a datetime that he wants to be reminded something. I will save his setting in a table in SQL Server 2000.
I want to create another thread running background whenever my program starts, detects and shows a message box to remind the user if it's the time to remind.
Can I use the control BackgroundWorker ?
I call the method "RunWorkerAsync" of BackgroundWorker in FormLoad event and "CancelAsync" in FormClosing.
and a bit of my source:
private void bckgrdWkrCaNhan_DoWork(object sender, DoWorkEventArgs e)
BackgroundWorker worker = sender as BackgroundWorker;
e.Result = Remind(worker, e);
private void bckgrdWkrCaNhan_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
// First, handle the case where an exception was thrown.
if (e.Error != null)
else if (e.Cancelled)
private string Remind(BackgroundWorker worker, DoWorkEventArgs e)
string sResult= "";
e.Cancel = true;
//connect to DB and process something to make a result string (sResult)//will be showed in the message box to remind user
sResult = ....;
the code above just start when formload, implement immediately, not really what I want. I want it to run all the time so it can check the system clock every minute to remind user on time. How can I do this?
Please help me.
Thanks a lot.
Sorry for my English.