Async
:private async void button1_Click_1(object sender, EventArgs e)
await Task.Run(() =>
{
//Insert the long running stuff here
Process.Start(path);
});
我创建Windows服务和安装项目。
[在安装Windows服务期间,我添加了一个Windows窗体,该窗体允许用户在项目文件夹中上传文件,但是当我单击按钮以上传文件时,我的Windows窗体始终处于状态[[无响应] >
我的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窗体,该窗体允许用户在项目文件夹中上载文件,但是当我单击...
Async
:private async void button1_Click_1(object sender, EventArgs e)
await Task.Run(() =>
{
//Insert the long running stuff here
Process.Start(path);
});