[問題] 關於多執行緒的問題
最近在寫一個讓程式自動更新的功能
實際上就只是進行檔案的複製貼上而已
但是放在單一執行緒下可以正常運作
多執行緒下就會直接讓程式結束
不知道是哪裡出問題
請大家幫我看看
CODE 如下
backgroundWorker1.RunWorkerAsync();
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
DirectoryCopy(g_strCopyLocal, g_strCopyBackup, true);
DirectoryCopy(g_strCopyServer, g_strCopyLocal, true);
}
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
// If the destination directory doesn't exist, create it.
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
try
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, true);
}
catch
{
}
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
if (subdir.Name != "UpGrade" || subdir.Name != "CheakVersion")
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}
}
請大家能給我一些方向
--
Sent from my Misaka 10032
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.71.170.97
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1428384508.A.293.html
推
04/07 14:49, , 1F
04/07 14:49, 1F
→
04/07 14:55, , 2F
04/07 14:55, 2F
推
04/07 15:03, , 3F
04/07 15:03, 3F
推
04/07 15:18, , 4F
04/07 15:18, 4F
→
04/07 16:00, , 5F
04/07 16:00, 5F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章