作者yj0803 (仁武田信玄)
看板C_Sharp
标题[问题] 关於多执行绪的问题
时间Tue Apr 7 13:28:25 2015
最近在写一个让程式自动更新的功能
实际上就只是进行档案的复制贴上而已
但是放在单一执行绪下可以正常运作
多执行绪下就会直接让程式结束
不知道是哪里出问题
请大家帮我看看
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://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1428384508.A.293.html
1F:推 TameFoxx: 直接让程式结束是什麽意思 感觉你用错东西了 04/07 14:49
2F:→ TameFoxx: 主执行绪没等BW跑完就先跑到Dispose了吗 04/07 14:55
3F:推 johnpage: 爸爸叫儿子买东西,却没有等他回来,就把门关起来。 04/07 15:03
4F:推 TameFoxx: 如果是这样那就根本不需要用多执行绪阿XD 04/07 15:18
5F:→ GoalBased: 好爸爸 04/07 16:00