现有一个程序,winform。在主页面中有一个button,button触发调用外部一个bat file
bat file执行完会将结果反馈到主页面的UI上。我希望在bat 运行期间,有一个进度条显示。
但是由于我button中调用的bat file是用process 调用的。所以UI假死,导致进度条无法加载。
Process process = new Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = strbatPath.ToString();
process.Start();
process.WaitForExit();
string returnValue = process.ExitCode.ToString();
if (process.HasExited)
{
//MessageBox.Show(process.ExitCode.ToString());
if (returnValue.Equals("0"))
{
process.Close();
//this.backgroundWorker1.CancelAsync();
this.TC1.Enabled = true;
ReadResult();
}
else
{
}
在网上查了很多,都说用多线程操作。但是我不理解。于是产生了下面的疑问
1.除了process 调用bat, 还有thread来调用的方法吗?因为起了一个thread调用进度条,那么就必须有另外一个thread来调用bat,对吗?
2.能给出一个伪代码来实现我上述的要求吗?有点搞糊涂了