我正在尝试创建一个加载窗口,该窗口将有一个进度条并在后台工作人员执行一些时间密集型工作时显示它。不幸的是,此加载窗口仅部分加载然后冻结,直到后台工作完成。如何解决此问题,以使加载窗口不会与后台进程冲突?
一个视觉示例:http: //i.imgur.com/1jQszPt.png
lw = new LoadWindow();
lw.Show();
worker.DoWork += delegate(object s, DoWorkEventArgs args)
{
/*Program-specific code*/
string theDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); /* get the folder location of the exe */
string filePath = theDirectory + "\\export.xml";
if (!File.Exists(filePath))
{
FileStream f = File.Create(filePath);
f.Close();
}
FileStream fileStream = File.Open(filePath, FileMode.Open);
fileStream.SetLength(0);
fileStream.Close();
FileStream fsWrite = File.Open(filePath, FileMode.Open, FileAccess.Write, FileShare.None);
StreamWriter sw = new StreamWriter(fsWrite);
Dispatcher.Invoke(new Action(delegate() {
/*Program-specific code*/
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/C svn log " + FolderPath.Text + " -v --xml");
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
using (System.Diagnostics.Process process = Process.Start(startInfo))
{
using (StreamReader reader = process.StandardOutput)
{
string outStr = reader.ReadToEnd();
sw.Write(outStr);
sw.Close();
fsWrite.Close();
reader.Close();
process.WaitForExit();
}
}
TicketIDChanged(sender, new TextChangedEventArgs(e.RoutedEvent, new UndoAction()));
}), DispatcherPriority.Background);
};
worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
lw.Hide();
};
worker.RunWorkerAsync();