有谁知道我如何从另一个线程更改窗体的窗口状态?这是我正在使用的代码:
private void button4_Click(object sender, EventArgs e)
{
string pathe = label1.Text;
string name = Path.GetFileName(pathe);
pathe = pathe.Replace(name, "");
string runpath = label2.Text;
Process process;
process = new Process();
process.EnableRaisingEvents = true;
process.Exited += new System.EventHandler(process_Exited);
process.StartInfo.FileName = @runpath;
process.StartInfo.WorkingDirectory = @pathe;
process.Start();
WindowState = FormWindowState.Minimized;
}
private void process_Exited(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
}
它的意思是运行一个程序并最小化,然后在程序关闭后返回正常状态。虽然我收到此错误“跨线程操作无效:控件'Form1'从创建它的线程以外的线程访问。” 知道如何让它工作吗?