diff --git a/PublishSite/PublishForm.cs b/PublishSite/PublishForm.cs index 20047e71..d6438a1c 100644 --- a/PublishSite/PublishForm.cs +++ b/PublishSite/PublishForm.cs @@ -38,7 +38,7 @@ namespace PublishSite .WriteTo.File("logs\\log.txt", rollingInterval: RollingInterval.Day) .CreateLogger(); - + uiContext = SynchronizationContext.Current; } @@ -52,6 +52,8 @@ namespace PublishSite public string Password = ""; + SynchronizationContext uiContext; + private void WinformLog(string message, Color? color = null) { if (InvokeRequired) @@ -637,7 +639,14 @@ namespace PublishSite private async void startServiceBtn_Click(object sender, EventArgs e) { - startServiceBtn.Enabled = false; + //startServiceBtn.Enabled = false; + + + uiContext.Post((state) => + { + // 访问控件并更新它们 + startServiceBtn.Enabled = false; + }, null); await Task.Run(() => { @@ -680,12 +689,22 @@ namespace PublishSite }); - startServiceBtn.Enabled = true; + uiContext.Post((state) => + { + // 访问控件并更新它们 + startServiceBtn.Enabled = true; + }, null); + //startServiceBtn.Enabled = true; } private async void stopServiceBtn_Click(object sender, EventArgs e) { - startServiceBtn.Enabled = false; + //startServiceBtn.Enabled = false; + uiContext.Post((state) => + { + // 访问控件并更新它们 + startServiceBtn.Enabled = false; + }, null); await Task.Run(() => { if (rb_local.Checked) @@ -726,7 +745,13 @@ namespace PublishSite } }); - startServiceBtn.Enabled = true; + //startServiceBtn.Enabled = true; + + uiContext.Post((state) => + { + // 访问控件并更新它们 + startServiceBtn.Enabled = true; + }, null); } #endregion @@ -969,7 +994,7 @@ namespace PublishSite private async void sshNetCorePublishBtn2_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(publishFolderTBox.Text) || !File.Exists(publishFolderTBox.Text)) + if (string.IsNullOrEmpty(publishFolderTBox.Text)) { WinformLog($"请选择存在的文件夹才能开始发布", Color.Red); return; @@ -995,8 +1020,14 @@ namespace PublishSite try { - //将文件夹里的内容打包成压缩包 - ZipFile.CreateFromDirectory(localSourceFolder, filePath); + await Task.Run( () => + { + //将文件夹里的内容打包成压缩包 + ZipFile.CreateFromDirectory(localSourceFolder, filePath); + + + }); + } catch (Exception ex) {