1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Fixed a potential problem with the update-thread keeping an application running even if shutdown was requested

This commit is contained in:
Darth Affe 2017-08-05 20:46:31 +02:00
parent 519bdbfe74
commit e814a1af29
2 changed files with 4 additions and 1 deletions

View File

@ -102,6 +102,9 @@ namespace RGB.NET.Core
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public void Dispose()
{ {
if (_updateTokenSource?.IsCancellationRequested == false)
_updateTokenSource.Cancel();
foreach (IRGBDevice device in _devices) foreach (IRGBDevice device in _devices)
try { device.Dispose(); } try { device.Dispose(); }
catch { /* We do what we can */ } catch { /* We do what we can */ }

View File

@ -66,7 +66,7 @@ namespace RGB.NET.Core
{ {
_updateTokenSource?.Dispose(); _updateTokenSource?.Dispose();
_updateTokenSource = new CancellationTokenSource(); _updateTokenSource = new CancellationTokenSource();
_updateTask = Task.Factory.StartNew(UpdateLoop, (_updateToken = _updateTokenSource.Token)); _updateTask = Task.Factory.StartNew(UpdateLoop, (_updateToken = _updateTokenSource.Token), TaskCreationOptions.LongRunning, TaskScheduler.Default);
} }
else if (!shouldRun && (_updateTask != null)) // Stop task else if (!shouldRun && (_updateTask != null)) // Stop task
{ {