hi i have come accross a problem that after the process completed i cannot start the copy process again once it have completed. It complains "The object have been disposed", My question is how can i check if the bw have been stoped and i can start another bw(oR create a new bw)? I used the GUI to make the bw, it generates this private BackgroundWorker bw; ... this.bw = new System.ComponentModel.BackgroundWorker(); ... this.bw.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bw_DoWork); this.bw.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bw_RunWorkerCompleted); ..... public static void copyDirectory(string Src, string Dst) // http://www.codeproject.com/KB/files/copydirectoriesrecursive.aspx { String[] Files; fmCopying.StartPosition.Equals("Center"); if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar) Dst += Path.DirectorySeparatorChar; if (!Directory.Exists(Dst)) Directory.CreateDirectory(Dst); Files = Directory.GetFileSystemEntries(Src); /* fmCopying.pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied. fmCopying.pBar1.Minimum = 1; // Set Maximum to the total number of files to copy. fmCopying.pBar1.Maximum = Files.Length; // Set the initial value of the ProgressBar. fmCopying.pBar1.Value = 2; // Set the Step property to a value of 1 to represent each file being copied. fmCopying.pBar1.Step = 1; */ foreach (string Element in Files) { fmCopying.Refresh(); // Sub directories if (Directory.Exists(Element)){ System.Threading.Thread.Sleep(1000); copyDirectory(Element, Dst + Path.GetFileName(Element)); fmCopying.Refresh(); fmCopying.lblCopying.Text =Element; fmCopying.lblCopying2.Text = Dst + Path.GetFileName(Element); fmCopying.Refresh(); } // Files in directory else { System.Threading.Thread.Sleep(1000); File.Copy(Element, Ds
daniel abcde
Posts
-
How to interrupt a method in c#? -
How to interrupt a method in c#?many thanks, Luc. I am now rewriting the Copy form and add Thread method to it, so when it starts it will open a new thread and start the copy method. But i don't quite get how to get Control.InvokeRequired and Control.Invoke works, can you please give a bit example or a bit explainlation of them? many thanks again! daniel
-
Validate user permissionsperhaps using LDAP ? My program can allow AD users to change their password by their own. I'm not sure does this works in your case. You can try.
-
How to interrupt a method in c#?If i click on the stop button the window will freeze and the copy process don't stop.. My though in the code maynot be the best way of doing it, any ideas are welcome, many thanks for your help :)
-
How to interrupt a method in c#?Hi, i'm writing a program about copy files from one place to other place. When the copy process start, it will shows up a form and tells user what file are being copied and there is a button to allow the user to stop the process. My problem is i cannot make the "stop" button works.The program code is like this: ======Copy Form====== private void StopButton_Click(object sender, EventArgs e) { frmTest.Stopcopying = true; return; } =======Main form(frmtest) ======================== .... public static bool Stopcopying = false; ... public static void copyDirectory(string Src, string Dst) { String[] Files; fmCopying.StartPosition.Equals("Center"); if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar) Dst += Path.DirectorySeparatorChar; if (!Directory.Exists(Dst)) Directory.CreateDirectory(Dst); Files = Directory.GetFileSystemEntries(Src); // int[] result = Array.FindAll(Files, delegate(int i){} frmCopying fmCopying1 = new frmCopying(); fmCopying1.Show(); foreach (string Element in Files) { fmCopying1.Refresh(); // Sub directories if (Directory.Exists(Element)){ if (frmTest.Stopcopying == true) { fmCopying1.Close(); return; } copyDirectory(Element, Dst + Path.GetFileName(Element)); fmCopying1.Refresh(); fmCopying1.lblCopying.Text =Element; fmCopying1.lblCopying2.Text = Dst + Path.GetFileName(Element); fmCopying1.Refresh(); } // Files in directory else { if (frmTest.Stopcopying == true) { fmCopying1.Close(); return; } File.Copy(Element, Dst + Path.GetFileName(Element), true); fmCopying1.Refresh(); fmCopying1.lblCopying.Text =Element; fmCopying1.lblCopying