0

I have a button to set the bool to false and then he shouldn't upload the files anymore automatic. But if I set it to true again, he should start to upload it his own, but it he doesn't.

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    while (automaticUpload)
    {
        //I do something here
    }
}

I set it to true using a button click

private void oNToolStripMenuItem_Click(object sender, EventArgs e)
{
    automaticUpload = true;
}

Edit:

I know I have to start the backgroundworker ^^ Or do you mean calling EnableUpload() again with the button click ?

private void EnableUpload()
    {
        backgroundWorker1.RunWorkerAsync();
    }
Clarais
  • 1
  • 3
  • 1
    What are you trying to achieve? – abatishchev Nov 05 '14 at 21:45
  • 1
    YOu need to actually start the backgroundworker thread – DJ Burb Nov 05 '14 at 21:45
  • I know I have to start the backgroundworker ^^ Or do you mean calling EnableUpload() again with the click ? – Clarais Nov 05 '14 at 21:47
  • 1
    similar to [1]: http://stackoverflow.com/questions/3065700/how-to-start-and-stop-a-continuously-running-background-worker-using-a-button – Matt Lengenfelder Nov 05 '14 at 21:49
  • Ofcourse, yes ! Omg, I'm to tired, thanks. – Clarais Nov 05 '14 at 21:51
  • oh ok. Just didn't see it in your code. – DJ Burb Nov 05 '14 at 22:00
  • @Clarais: ugh. Please don't follow the marked answer in that linked question. It leaves a `BackgroundWorker` running continuously; when the controlling flag is not set, it's basically a tight loop. It's bad enough for the worker thread method to not be allowed to return in a timely fashion, but it's even worse to tie up a CPU core doing nothing like that. – Peter Duniho Nov 05 '14 at 22:07
  • @Clarais: as far as the actual question goes, you haven't provided enough information to know what the correct implementation here is. But for sure, it doesn't involve letting a `BackgroundWorker` sit around in a loop waiting for some work to do. Instead, whatever trigger actually causes an "automatic upload" to occur, should simply first check the `automaticUpload` flag and do the upload only when the flag is set. Alternatively, depending on the trigger, you may have a way to simply not allow the trigger to occur unless the flag is set. – Peter Duniho Nov 05 '14 at 22:09
  • Could you link me a better solution ? – Clarais Nov 05 '14 at 22:10
  • @Clarais I saw that you have deleted your "C# webbrowser flash isn't working" question, If you want I can help you. – akmozo Jan 08 '15 at 23:00
  • @akmozo I already did it myself, but thanks. :) – Clarais Jan 09 '15 at 17:40

0 Answers0