summaryrefslogtreecommitdiff
path: root/Source/Core/WinUpdater/WinUI.cpp
diff options
context:
space:
mode:
authorSilent <zdanio95@gmail.com>2019-06-24 20:49:18 +0200
committerSilent <zdanio95@gmail.com>2019-07-22 19:28:20 +0200
commitd355abaf0cb064963b9c6a4b99d5c70fe61ebf5a (patch)
tree4dc6496063b3e6a3a635b083aa6a14a2f181cce3 /Source/Core/WinUpdater/WinUI.cpp
parent3f1ba830e7718be59fe7a597b80764af6f083c79 (diff)
WinUpdater: Improved exit synchronization on Windows - now joins a thread instead of using flags to signal
Diffstat (limited to 'Source/Core/WinUpdater/WinUI.cpp')
-rw-r--r--Source/Core/WinUpdater/WinUI.cpp28
1 files changed, 12 insertions, 16 deletions
diff --git a/Source/Core/WinUpdater/WinUI.cpp b/Source/Core/WinUpdater/WinUI.cpp
index b187b77a42..d65b00033d 100644
--- a/Source/Core/WinUpdater/WinUI.cpp
+++ b/Source/Core/WinUpdater/WinUI.cpp
@@ -12,7 +12,6 @@
#include <ShObjIdl.h>
#include <shellapi.h>
-#include "Common/Flag.h"
#include "Common/StringUtil.h"
namespace
@@ -23,7 +22,7 @@ HWND total_progressbar_handle = nullptr;
HWND current_progressbar_handle = nullptr;
ITaskbarList3* taskbar_list = nullptr;
-Common::Flag running;
+std::thread ui_thread;
int GetWindowHeight(HWND hwnd)
{
@@ -201,12 +200,16 @@ void SetDescription(const std::string& text)
void MessageLoop()
{
- running.Set();
-
if (!InitWindow())
{
- running.Clear();
MessageBox(nullptr, L"Window init failed!", L"", MB_ICONERROR);
+ // Destroying the parent (if exists) destroys all children windows
+ if (window_handle)
+ {
+ DestroyWindow(window_handle);
+ window_handle = nullptr;
+ }
+ return;
}
SetTotalMarquee(true);
@@ -218,26 +221,19 @@ void MessageLoop()
TranslateMessage(&msg);
DispatchMessage(&msg);
}
-
- running.Clear();
}
void Init()
{
- std::thread thread(MessageLoop);
- thread.detach();
+ ui_thread = std::thread(MessageLoop);
}
void Stop()
{
- if (!running.IsSet())
- return;
+ if (window_handle)
+ PostMessage(window_handle, WM_CLOSE, 0, 0);
- PostMessage(window_handle, WM_CLOSE, 0, 0);
-
- while (running.IsSet())
- {
- }
+ ui_thread.join();
}
void LaunchApplication(std::string path)