[问题] 关于多执行绪的问题

楼主: yj0803 (台中居正广)   2015-04-07 13:28:25
最近在写一个让程式自动更新的功能
实际上就只是进行档案的复制贴上而已
但是放在单一执行绪下可以正常运作
多执行绪下就会直接让程式结束
不知道是哪里出问题
请大家帮我看看
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);
}
}
}
}
请大家能给我一些方向
作者: TameFoxx (foxx)   2015-04-07 14:49:00
直接让程式结束是什么意思 感觉你用错东西了主执行绪没等BW跑完就先跑到Dispose了吗
作者: johnpage (johnpage)   2015-04-07 15:03:00
爸爸叫儿子买东西,却没有等他回来,就把门关起来。
作者: TameFoxx (foxx)   2015-04-07 15:18:00
如果是这样那就根本不需要用多执行绪阿XD
作者: GoalBased (Artificail Intelligence)   2015-04-07 16:00:00
好爸爸

Links booklink

Contact Us: admin [ a t ] ucptt.com