使用Winform Form Window (FixedDialog with toolbars)
提供安装和卸载应用程序的选项。(Windows exe应用程序)
当用户单击要安装/卸载的按钮时,该窗口既不能移动也不能最小化。也就是说,在未完成为活动引发的事件之前,它会被卡住,无法在窗体窗口上执行任何操作。
事件按下面的方式添加,这样做是独立的。在form1.designer.cs中
private void InitializeComponent(string defaultPath)
{
//Other steps
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.InstallButton.Click += new System.EventHandler(this.InstallButton_Click);
this.UnInstallButton.Click += new System.EventHandler(this.UnInstallButton_Click);
}
例如:函数InstallButton_Click
有多个安装步骤,用于复制文件和执行其他工作,大约需要半分钟。在此期间,它不允许移动或最小化窗口。在form.cs中
private void InstallButton_Click(object sender, EventArgs e)
{
//Multiple steps for installation
//takes around 20-30 seconds to complete
}
这个问题类似于提到的here,但在这里看不到一个可接受的答案。
是否有允许用户最小化或移动窗口的方法?
发布于 2021-03-18 12:11:24
可以使用Here多种方法。
由于代码涉及一些步骤,所以不能直接使用GUI控件。
由于几乎所有的解决方案都是基于asynchronous
原则的,所以它常常抛出一个错误,Cross-thread operation not valid: Control 'InstallButton' accessed from a thread other than the thread it was created on.
。
为了避免这种情况,隔离了涉及GUI控制访问和执行它们的步骤,同时使用sequentially
方法运行asynchronously
作为保持独立的代码。对于GI,它的执行时间是可以忽略的。
//Logic to update control
Task.Run(()=>
{
//Remaining logic
});
https://stackoverflow.com/questions/66688138
复制相似问题