Windows表单无响应:如何解决此问题?

问题描述 投票:0回答:3

我创建Windows服务和安装项目。

[在安装Windows服务期间,我添加了一个Windows窗体,该窗体允许用户在项目文件夹中上传文件,但是当我单击按钮以上传文件时,我的Windows窗体始终处于状态[[无响应] >not responding

我的Windows服务的ProjectInstaller

public override void Install(IDictionary stateSaver) { base.Install(stateSaver); Form1 validationForm = new Form1(); validationForm.ShowDialog(); }

Windows窗体

public Form1() { InitializeComponent(); } private void button1_Click_1(object sender, EventArgs e) { try { OpenFileDialog fileDialog = new OpenFileDialog(); //fileDialog.Filter = "Dat files |*.dat"; fileDialog.Multiselect = false; if (fileDialog.ShowDialog() == DialogResult.OK) { var path = fileDialog.FileName; Process.Start(path); } } catch (Exception) { MessageBox.Show("An error occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
我创建Windows服务和安装项目。在Windows服务的安装过程中,我添加了一个Windows窗体,该窗体允许用户在项目文件夹中上载文件,但是当我单击...
c# winforms windows-services setup-project
3个回答
0
投票

4
投票

您的用户界面由于长时间运行而被锁定,这就是为什么您看到“未响应”的原因]]
标记您的点击Async

private async void button1_Click_1(object sender, EventArgs e)

await Task.Run(() => { //Insert the long running stuff here Process.Start(path); });


1
投票
© www.soinside.com 2019 - 2024. All rights reserved.