Hi , i have got CopyFile and Directory project.But when i started to copy Gui is freezing.I cant do anything file copying.So i found my solution at BackgroundWorker Component.But i got a problem with this component too.There are 3 radio button and command button.When i clicked command button its checking if radiobutton1 checked or else radiobutton 2 checked or else radiobutton 3 checked.If radiobuton1 checked do a lot things or radiobutton 2 chechked do another things etc.There are 3 backgroundworker for 3 radiobutton.When i chechked radiobutton 1 backgroundworker 1 dowork event working.When i checked radiobutton2 backgroundworker 2 dowork event working. etc.... My problem is when i chechked radiobutton1 and click commmand button.Starting backgroundworker1 do work event but its also continue to control if radiobutton2 checked or not..Not stopping so iam getting errors.My codes are ;
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 == "" && 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 <= 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();
}