Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply CallFuncConsideringUIThreads as possible as I can #567

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 23 additions & 68 deletions src/NetSparkle/SparkleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,41 +767,28 @@ private void OnToastClick(List<AppCastItem> updates)

private void ShowUpdateAvailableWindow(List<AppCastItem> updates, bool isUpdateAlreadyDownloaded = false)
{
if (UpdateAvailableWindow != null)
CallFuncConsideringUIThreads(() =>
{
// close old window
if (ShowsUIOnMainThread)
{
_syncContext.Post((state) =>
{
UpdateAvailableWindow.Close();
UpdateAvailableWindow = null;
}, null);
}
else
{
if (UpdateAvailableWindow != null)
UpdateAvailableWindow.Close();
UpdateAvailableWindow = null;
}
}
UpdateAvailableWindow = null;

// create the form
Thread thread = new Thread(() =>
{
try
// define action
Action<object> showSparkleUI = (state) =>
{
// define action
Action<object> showSparkleUI = (state) =>
{
UpdateAvailableWindow = UIFactory?.CreateUpdateAvailableWindow(this, updates, isUpdateAlreadyDownloaded);
UpdateAvailableWindow = UIFactory?.CreateUpdateAvailableWindow(this, updates, isUpdateAlreadyDownloaded);

if (UpdateAvailableWindow != null)
{
UpdateAvailableWindow.UserResponded += OnUpdateWindowUserResponded;
UpdateAvailableWindow.Show(ShowsUIOnMainThread);
}
};
if (UpdateAvailableWindow != null)
{
UpdateAvailableWindow.UserResponded += OnUpdateWindowUserResponded;
UpdateAvailableWindow.Show(ShowsUIOnMainThread);
}
};

// create the form
try
{
// call action
if (ShowsUIOnMainThread)
{
Expand All @@ -817,15 +804,6 @@ private void ShowUpdateAvailableWindow(List<AppCastItem> updates, bool isUpdateA
LogWriter.PrintMessage("Error showing sparkle form: {0}", e.Message);
}
});
#if NETFRAMEWORK
thread.SetApartmentState(ApartmentState.STA);
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
thread.SetApartmentState(ApartmentState.STA); // only supported on Windows
}
#endif
thread.Start();
}

/// <summary>
Expand Down Expand Up @@ -1038,47 +1016,24 @@ private void CreateAndShowProgressWindow(AppCastItem castItem, bool shouldShowAs
UpdateDownloader.DownloadProgressChanged += ProgressWindow.OnDownloadProgressChanged;
if (shouldShowAsDownloadedAlready)
{
ProgressWindow?.FinishedDownloadingFile(true);
_syncContext.Post((state2) =>
CallFuncConsideringUIThreads(() =>
{
ProgressWindow?.FinishedDownloadingFile(true);
OnDownloadFinished(null, new AsyncCompletedEventArgs(null, false, null));
_actionToRunOnProgressWindowShown?.Invoke();
_actionToRunOnProgressWindowShown = null;
}, null);
});
}
}
};
}
Thread thread = new Thread(() =>
{
CallFuncConsideringUIThreads(() => {
// call action
if (ShowsUIOnMainThread)
{
_syncContext.Post((state) =>
{
showSparkleDownloadUI(null);
_actionToRunOnProgressWindowShown?.Invoke();
_actionToRunOnProgressWindowShown = null;
ProgressWindow?.Show(ShowsUIOnMainThread);
}, null);
}
else
{
showSparkleDownloadUI(null);
_actionToRunOnProgressWindowShown?.Invoke();
_actionToRunOnProgressWindowShown = null;
ProgressWindow?.Show(ShowsUIOnMainThread);
}
showSparkleDownloadUI(null);
_actionToRunOnProgressWindowShown?.Invoke();
_actionToRunOnProgressWindowShown = null;
ProgressWindow?.Show(ShowsUIOnMainThread);
});
#if NETFRAMEWORK
thread.SetApartmentState(ApartmentState.STA);
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
thread.SetApartmentState(ApartmentState.STA); // only supported on Windows
}
#endif
thread.Start();
}

private async void ProgressWindowCompleted(object sender, DownloadInstallEventArgs args)
Expand Down