void startOfThread2(ThreadParams tp) { using (FileStream fsSource = new FileStream(tp.Source, FileMode.Open, FileAccess.Read)) using (FileStream fsDest = new FileStream(tp.Dest, FileMode.CreateNew, FileAccess.Write)) { byte[] buff = new byte[_buffsize]; int readsize = 0; while ((readsize = fsSource.Read(buff, 0, _buffsize)) > 0) { try { fsDest.Write(buff, 0, readsize); } catch (Exception ex) { // If the writing failed, ask and retry if (!AskRetry(ex.Message)) { return; } } } } }
void startOfThread(object obj) { ThreadParams tp = (ThreadParams)obj; try { startOfThread2(tp); Info(Properties.Resources.COPY_SUCCEEDED); } catch (Exception ex) { Alert(ex.Message); return; } tp.Parent.BeginInvoke(new Action(onEndThread)); }