Fix race condition on shutdown

Closes #923
This commit is contained in:
MaxXor 2021-02-08 20:09:19 +01:00
parent 9520cd70ff
commit 2dbf7fd8fa
3 changed files with 19 additions and 8 deletions

View File

@ -75,7 +75,15 @@ public void ConnectLoop()
while (Connected) // hold client open
{
_token.WaitHandle.WaitOne(1000);
try
{
_token.WaitHandle.WaitOne(1000);
}
catch (Exception e) when (e is NullReferenceException || e is ObjectDisposedException)
{
Disconnect();
return;
}
}
if (_token.IsCancellationRequested)

View File

@ -104,13 +104,13 @@ public void Run()
{
// decrypt and verify the settings
if (!Settings.Initialize())
Application.Exit();
Environment.Exit(1);
ApplicationMutex = new SingleInstanceMutex(Settings.MUTEX);
// check if process with same mutex is already running on system
if (!ApplicationMutex.CreatedNew)
Application.Exit();
Environment.Exit(2);
FileHelper.DeleteZoneIdentifier(Application.ExecutablePath);
@ -124,7 +124,7 @@ public void Run()
try
{
installer.Install();
Application.Exit();
Environment.Exit(3);
}
catch (Exception e)
{
@ -165,7 +165,7 @@ public void Run()
// Start connection loop on new thread and dispose application once client exits.
// This is required to keep the UI thread responsive and run the message loop.
_connectClient.ConnectLoop();
Application.Exit();
Environment.Exit(0);
}).Start();
}
}

View File

@ -64,14 +64,14 @@ public void Start()
/// </summary>
private void UserActivityThread()
{
while (!_token.WaitHandle.WaitOne(10))
try
{
if (IsUserIdle())
{
if (_lastUserStatus != UserStatus.Idle)
{
_lastUserStatus = UserStatus.Idle;
_client.Send(new SetUserStatus {Message = _lastUserStatus});
_client.Send(new SetUserStatus { Message = _lastUserStatus });
}
}
else
@ -79,10 +79,13 @@ private void UserActivityThread()
if (_lastUserStatus != UserStatus.Active)
{
_lastUserStatus = UserStatus.Active;
_client.Send(new SetUserStatus {Message = _lastUserStatus});
_client.Send(new SetUserStatus { Message = _lastUserStatus });
}
}
}
catch (Exception e) when (e is NullReferenceException || e is ObjectDisposedException)
{
}
}
/// <summary>