Click here to Skip to main content
15,913,055 members
Home / Discussions / C#
   

C#

 
QuestionBackgroundworker Pin
arkiboys10-Mar-11 22:43
arkiboys10-Mar-11 22:43 
Hi,
My code below is in a windows service:
Can you see from the code here, why the backgroundworker_DoWork only gets called once?
I expect it to be called every 200 milliseconds.

There is a timer which gets called every few seconds i.e. OnElapsedTime which does other checks.
But I am trying to have a backgroundworker to run the method GetStatus(); every 200 milliseconds
private static BackgroundWorker _backgroundWorker;

internal static BackgroundWorker BackgroundWorker { get { return _backgroundWorker; } }

private void Initialize()
{
_backgroundWorker = new BackgroundWorker();
_backgroundWorker.WorkerSupportsCancellation = true;
_backgroundWorker.WorkerReportsProgress = true;
_backgroundWorker.DoWork += new DoWorkEventHandler(BackgroundWorker_DoWork);                                
_backgroundWorker.RunWorkerAsync();

timer.Elapsed += new System.Timers.ElapsedEventHandler(OnElapsedTime);
timer.Enabled = true;
}

private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (_backgroundWorker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            GetStatus();
            Thread.Sleep(200);
        }    

AnswerRe: Backgroundworker Pin
musefan10-Mar-11 23:22
musefan10-Mar-11 23:22 
GeneralRe: Backgroundworker Pin
arkiboys10-Mar-11 23:31
arkiboys10-Mar-11 23:31 
GeneralRe: Backgroundworker Pin
Eddy Vluggen10-Mar-11 23:39
professionalEddy Vluggen10-Mar-11 23:39 
GeneralRe: Backgroundworker Pin
musefan10-Mar-11 23:47
musefan10-Mar-11 23:47 
GeneralRe: Backgroundworker Pin
arkiboys11-Mar-11 0:43
arkiboys11-Mar-11 0:43 
AnswerRe: Backgroundworker Pin
Pete O'Hanlon10-Mar-11 23:25
mvePete O'Hanlon10-Mar-11 23:25 
GeneralRe: Backgroundworker Pin
arkiboys10-Mar-11 23:31
arkiboys10-Mar-11 23:31 
GeneralRe: Backgroundworker Pin
Luc Pattyn11-Mar-11 0:55
sitebuilderLuc Pattyn11-Mar-11 0:55 
GeneralRe: Backgroundworker Pin
Pete O'Hanlon11-Mar-11 1:04
mvePete O'Hanlon11-Mar-11 1:04 
GeneralRe: Backgroundworker Pin
arkiboys11-Mar-11 1:16
arkiboys11-Mar-11 1:16 
GeneralRe: Backgroundworker Pin
SledgeHammer0111-Mar-11 6:35
SledgeHammer0111-Mar-11 6:35 
AnswerRe: Backgroundworker Pin
Geoff Williams10-Mar-11 23:34
Geoff Williams10-Mar-11 23:34 
GeneralRe: Backgroundworker Pin
arkiboys10-Mar-11 23:40
arkiboys10-Mar-11 23:40 
GeneralRe: Backgroundworker Pin
Geoff Williams10-Mar-11 23:42
Geoff Williams10-Mar-11 23:42 
GeneralRe: Backgroundworker Pin
arkiboys11-Mar-11 0:04
arkiboys11-Mar-11 0:04 
GeneralRe: Backgroundworker Pin
Geoff Williams11-Mar-11 0:15
Geoff Williams11-Mar-11 0:15 
GeneralRe: Backgroundworker Pin
arkiboys11-Mar-11 0:42
arkiboys11-Mar-11 0:42 
QuestionIntegrate WebCam in ASPX Pin
The_Collector10-Mar-11 16:24
The_Collector10-Mar-11 16:24 
AnswerRe: Integrate WebCam in ASPX Pin
Pravin Patil, Mumbai10-Mar-11 20:38
Pravin Patil, Mumbai10-Mar-11 20:38 
GeneralRe: Integrate WebCam in ASPX Pin
The_Collector10-Mar-11 20:58
The_Collector10-Mar-11 20:58 
GeneralRe: Integrate WebCam in ASPX Pin
Richard MacCutchan10-Mar-11 22:42
mveRichard MacCutchan10-Mar-11 22:42 
GeneralRe: Integrate WebCam in ASPX Pin
The_Collector11-Mar-11 15:04
The_Collector11-Mar-11 15:04 
GeneralRe: Integrate WebCam in ASPX Pin
Richard MacCutchan11-Mar-11 21:52
mveRichard MacCutchan11-Mar-11 21:52 
GeneralRe: Integrate WebCam in ASPX Pin
The_Collector11-Mar-11 22:33
The_Collector11-Mar-11 22:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.