我的问题是,当我单击文件上传时,我的文件没有上传。而且表单也不会关闭。
我的Windows服务的ProjectInstaller
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
Form1 validationForm = new Form1(Context.Parameters["TARGETDIR"]);
validationForm.ShowDialog();
}
Windows窗体
private static string folderToUploadFile = string.Empty;
public Form1(string folder)
{
InitializeComponent();
folderToUploadFile = folder;
label1.Text = folder;
}
private void button1_Click_1(object sender, EventArgs e)
{
var task = new Thread(() => {
try
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Filter = "Dat files |*.dat";
fileDialog.Multiselect = false;
if (fileDialog.ShowDialog() == DialogResult.OK)
{
var filename = fileDialog.FileName;
Task.Run(() =>
{
File.Copy(filename, folderToUploadFile);
this.Close();
});
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
});
task.SetApartmentState(ApartmentState.STA);
task.Start();
task.Join();
}
我创建Windows服务和安装项目。我创建一个Windows表单以上传安装项目的文件。我的问题是,当我单击文件上传时,我的文件没有上传。形式...