mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Merge remote-tracking branch 'origin/Core/ThreadSafety' into Development
This commit is contained in:
commit
9958da79d8
@ -14,6 +14,8 @@ namespace RGB.NET.Core
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private object _lock = new object();
|
||||
|
||||
private CancellationTokenSource _updateTokenSource;
|
||||
private CancellationToken _updateToken;
|
||||
private Task _updateTask;
|
||||
@ -58,6 +60,8 @@ namespace RGB.NET.Core
|
||||
/// Starts the trigger if needed, causing it to performing updates.
|
||||
/// </summary>
|
||||
public void Start()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_updateTask == null)
|
||||
{
|
||||
@ -66,20 +70,25 @@ namespace RGB.NET.Core
|
||||
_updateTask = Task.Factory.StartNew(UpdateLoop, (_updateToken = _updateTokenSource.Token), TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the trigger if running, causing it to stop performing updates.
|
||||
/// </summary>
|
||||
public async void Stop()
|
||||
public void Stop()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_updateTask != null)
|
||||
{
|
||||
_updateTokenSource.Cancel();
|
||||
await _updateTask;
|
||||
// ReSharper disable once MethodSupportsCancellation
|
||||
_updateTask.Wait();
|
||||
_updateTask.Dispose();
|
||||
_updateTask = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLoop()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user