Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I fix this issue involving BackgroundWorkers in C#?
    text
    copied!<p>I have a CopyFile and Directory project. But when I started to copy Gui, it freezes. I can't do anything with file copying. So I found my solution at BackgroundWorker Component. But I have a problem with this component too.</p> <p>There are 3 radio buttons and command button. When I click the command button, it's checking if <code>radiobutton1</code> is checked or else if <code>radiobutton2</code> checked or else if <code>radiobutton3</code> is checked. If <code>radiobutton1</code> is checked, do a lot things, or if <code>radiobutton2</code> checked, do another thing, etc. There are 3 backgroundworkers for 3 radiobuttons. When I checked <code>radiobutton1</code>, <code>backgroundworker1</code> dowork event working. When I checked <code>radiobutton2</code>, <code>backgroundworker2</code> dowork event working. etc...</p> <p>My problem is when I checked <code>radiobutton1</code> and click commmand button. Starting <code>backgroundworker1</code> do work event but it's also continuing to control if <code>radiobutton2</code> is checked or not. It is not stopping, so I am getting errors. My code is below:</p> <pre><code>private void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked) { backgroundWorker1.RunWorkerAsync(); } if (radioButton2.Checked) { StreamReader sr = new StreamReader(Application.StartupPath + @"\hakimler.txt"); while ((satir = sr.ReadLine()) != null) { try { bool copy = CopyDirectory(DosyaYolu.kaynak, @"\\" + satir + @"" + DosyaYolu.hedef, true); if (copy) { kopya += 1; } else { sw.WriteLine(satir); } } catch (Exception) { } } sw.Close(); MessageBox.Show("İşlem tamamlandı", "İşlem Sonu", MessageBoxButtons.OK, MessageBoxIcon.Information); lblkopya.Text = "Başarıyla tamamlanan iş sayısı : " + kopya.ToString(); return; } if (chkPersonel.Checked == true) { StreamReader sr = new StreamReader(Application.StartupPath + @"\personel.txt"); while ((satir = sr.ReadLine()) != null) { try { bool copy = CopyDirectory(DosyaYolu.kaynak, @"\\ab04500-" + satir + @"" + DosyaYolu.hedef, true); //bool copy = CopyDirectory(Application.StartupPath + @"\TELEFON REHBERİ", @"\\" + satir + @"\c$\Documents and Settings\All Users\Start Menu", true); if (copy) { kopya += 1; } else { sw.WriteLine(satir); } } catch (Exception) { } } sw.Close(); MessageBox.Show("İşlem tamamlandı", "İşlem Sonu", MessageBoxButtons.OK, MessageBoxIcon.Information); lblkopya.Text = "Başarıyla tamamlanan iş sayısı : " + kopya.ToString(); return; } else { if (txtBilgisayar.Text == "" &amp;&amp; txtDongu.Text == "") { MessageBox.Show("Boşlukları dolduralım bi zahmet :@", "Bilgisayar Kodlarını girelim lütfen!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } bilgisayar = Convert.ToInt32(txtBilgisayar.Text); dongu = Convert.ToInt32(txtDongu.Text); for (int i = bilgisayar; i &lt;= dongu; i++) { try { bool copy = CopyDirectory(DosyaYolu.kaynak, @"\\ab04500-" + bilgisayar + @"" + DosyaYolu.hedef, true); if (copy) { kopya += 1; } else { sw.WriteLine(satir); } } catch (Exception) { } if (i == dongu) { sw.Close(); MessageBox.Show("İşlem tamamlandı", "İşlem Sonu", MessageBoxButtons.OK, MessageBoxIcon.Information); lblkopya.Text = "Başarıyla tamamlanan iş sayısı : " + kopya.ToString(); } bilgisayar += 1; } } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { sw = new StreamWriter(DateTime.Today.ToShortDateString().ToString() + "_ulasmayanlar.txt", true); StreamReader sr = new StreamReader(Application.StartupPath + @"\savcilar.txt"); while ((satir = sr.ReadLine()) != null) { try { bool copy = CopyDirectory(DosyaYolu.kaynak, @"\\" + satir + @"" + DosyaYolu.hedef, true); //bool copy = CopyDirectory(Application.StartupPath + @"\TELEFON REHBERİ", @"\\" + satir + @"\c$\Documents and Settings\All Users\Start Menu", true); if (copy) { kopya += 1; } else { sw.WriteLine(satir); } } catch (Exception) { } } } private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { sw.Close(); MessageBox.Show("İşlem tamamlandı", "İşlem Sonu", MessageBoxButtons.OK, MessageBoxIcon.Information); lblkopya.Text = "Başarıyla tamamlanan iş sayısı : " + kopya.ToString(); } </code></pre> <hr> <p>its control if radiobutton1 chechked or not if its checked true its start bgworkers do work event and its going to continue if radiobutton2 checked or not if radiobutton3 checked or not blabla its not stopping when its see radiobutton1 checked true.</p> <hr> <p>yes i want to stop controlling the another radiobutton's chechked true or not.if <strong>radiobutton1's chechked is true</strong> only do backgroundworkers dowork event and STOP.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload