目錄間複製檔案的執行緒實現

2021-04-27 08:42:16 字數 1591 閱讀 3087

**********===普通方案***************====

private void button1_click(object sender, eventargs e)

this.label1.text = "複製完成,共手複製檔案" + files.length.tostring() + "個";

} 你的邏輯類

public class fileoperator }

**********下面是多執行緒的方案***************==

private void button1_click(object sender, eventargs e)

); }

private void startcopy(object path)

));

foreach(fileinfo file in files )

));

//this.label1.refresh();

fileoperator.copyfile(file.fullname, dir2.fullname + "//" + file.name);

this.progressbar1.invoke(new methodinvoker(delegate ));

} this.label1.invoke(new methodinvoker(delegate ));

} }

public class fileoperator }

********************====下面是非同步方案********************==

定義乙個委託

delegate void copyhandler(string file1, string file1);

呼叫委託的begininvoke和endinvoke

具體**如下:

private void button1_click(object sender, eventargs e)

); }

//非同步委託物件

delegate void copyhandler(string file1, string file2);

private void startcopy(object path)

));

copyhandler copyhandler = new copyhandler(fileoperator.copyfile);

foreach (fileinfo file in files) }

private void asynccallback(iasyncresult result)

));

asyncresult r = (asyncresult)result;

copyhandler handler = (copyhandler)r.asyncdelegate;

handler.endinvoke(result);

this.progressbar1.invoke(new methodinvoker(delegate ));

} }

public class fileoperator }

實現目錄拷貝 複製目錄 複製檔案

include include include include include include include ifndef debug define pdebug fmt,args.do while 0 else define pdebug fmt,args.printf s d fmt,func...

檔案目錄複製

private void copydir string srcpath string aimpath 判斷目標目錄是否存在如果不存在則新建 if system.io directory exists aimpath 得到源目錄的檔案列表,該裡面是包含檔案以及目錄路徑的乙個陣列 如果你指向copy目標...

多執行緒複製檔案

include include include include define crt secure no warnings using namespace std critical section g csthreadcode volatile long g nnum 全域性資源 struct th...