我需要寫一個程式,要對15個不同路徑下的目錄進行操作,需要將這些目錄中的文件(文件是隨機產生)COPY到相對應的15個目錄下。
我想通過Thread來實現(環境是vs2003),代碼如下:
Thread a = new Thread(new ThreadStart(1)); 
a.IsBackground=true; 
a.Start(); 
Thread b = new Thread(new ThreadStart(2)); 
b.IsBackground=true; 
b.Start(); 
.......... 直到15為止............
調用代碼如下:
while (true)  

System.Threading.Thread.Sleep(10000);
System.IO.DirectoryInfo _DI2 = new DirectoryInfo(@"d:\3"); 
FileInfo[] _files2 = _DI2.GetFiles(); 
foreach(FileInfo _file2 in _files2) 

string filenamec=_file2.Name; 
string pathc=@"d:\3\"+filenamec; 
if(File.Exists(pathc)) 

try 

_file2.CopyTo(@"e:\4\" + _file2.Name,true); 
_file2.CopyTo(@"e:\5\" + _file2.Name,true); 
File.Delete(@"d:\3\"+_file2.Name); this.listBox1.Items.Add("Thie file copy OK:" + _file2.Name); 

catch (Exception ex) 

string errorinfo2=ex.Message; 
this.listBox1.Items.Add("Thie file copy Fail:" + _file2.Name + errorinfo2); string errorfile2=_file2.Name; 
string path4 = @"d:\3\"+_file2.Name; 
string path5 = @"d:\4\"+_file2.Name; 
if (File.Exists(path5)) 
File.Delete(path5); 
File.Move(path4,path5);             }} } } 有什麼辦法可以實現我的目的,又來將效率提高呢?