Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:08:21+00:00 2026-05-11T07:08:21+00:00

I have a CopyFile and Directory project. But when I started to copy Gui,

  • 0

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.

There are 3 radio buttons and command button. When I click the command button, it’s checking if radiobutton1 is checked or else if radiobutton2 checked or else if radiobutton3 is checked. If radiobutton1 is checked, do a lot things, or if radiobutton2 checked, do another thing, etc. There are 3 backgroundworkers for 3 radiobuttons. When I checked radiobutton1, backgroundworker1 dowork event working. When I checked radiobutton2, backgroundworker2 dowork event working. etc…

My problem is when I checked radiobutton1 and click commmand button. Starting backgroundworker1 do work event but it’s also continuing to control if radiobutton2 is checked or not. It is not stopping, so I am getting errors. My code is below:

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(); } 

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.


yes i want to stop controlling the another radiobutton’s chechked true or not.if radiobutton1’s chechked is true only do backgroundworkers dowork event and STOP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:08:22+00:00Added an answer on May 11, 2026 at 7:08 am

    I’m not quite sure what your problem exactly is, but in your code if your radioButton1 is Checked then the Background worker will do it’s thing, else it won’t. Isn’t that what you want?

    I don’t see any code for other radio buttons you mention.


    Ah, so you want to stop the background workers when you check antoher radio button? In your dowork() method you’ll have to check if bg.CancellationPending == true and exit the method if it is.

    Also you have to set WorkerSupportsCancellation to true after you initialize the BG worker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found a small snippet for doing a recursive file copy in C#, but
Trying to write a simple C# script to copy file to directory one level
I have a list of file names, and I want to search a directory
I have a small question: For example I'm using System.IO.File.Copy() method from .NET Framework.
I have this bit of powershell script but i can't get the $DirectoryName to
I have the code to copy a file to another location. public static void
i am just trying to use copyfile to copy a file, it is as
I use os.remove() for deleting a file, and shutil.copyfile() for copying a file. Sometimes
I have a directory on my local machine that I would like to copy
I have a java code for copy file from one folder to another folder.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.