public bool EnableMultiserver { get { return _enableMultiserver; } set { SetValue(ref _enableMultiserver, value); } }
private bool _enableMultiserver = false;
/// <summary> Gets or sets the max buffer length (in milliseconds) for outgoing voice packets. This value is the target maximum but is not guaranteed, the buffer will often go slightly above this value. </summary>
/// <summary> Gets or sets the max buffer length (in milliseconds) for outgoing voice packets. </summary>
public int BufferLength { get { return _bufferLength; } set { SetValue(ref _bufferLength, value); } }
/// <summary> Helper class used to manage several tasks and keep them in sync. If any single task errors or stops, all other tasks will also be stopped. </summary>
public sealed class TaskManager
{
private readonly object _lock;
private readonly AsyncLock _lock;
private readonly Func<Task> _stopAction;
private CancellationTokenSource _cancelSource;
@@ -24,7 +25,7 @@ namespace Discord
internal TaskManager()
{
_lock = new object();
_lock = new AsyncLock();
}
public TaskManager(Action stopAction)
: this()
@@ -45,7 +46,7 @@ namespace Discord
if (task != null)
await Stop().ConfigureAwait(false);
lock (_lock)
using (await _lock.LockAsync())
{
_cancelSource = cancelSource;
@@ -88,7 +89,7 @@ namespace Discord
public void SignalStop(bool isExpected = false)
{
lock (_lock)
using (_lock.Lock())
{
if (isExpected)
_wasStopExpected = true;
@@ -100,28 +101,27 @@ namespace Discord
_cancelSource.Cancel();
}
}
public Task Stop(bool isExpected = false)
public async Task Stop(bool isExpected = false)
{
Task task;
lock (_lock)
using (await _lock.LockAsync())
{
if (isExpected)
_wasStopExpected = true;
//Cache the task so we still have something to await if Cleanup is run really quickly
task = _task;
if (task == null) return TaskHelper.CompletedTask; //Are we running?
if (_cancelSource.IsCancellationRequested) return task;
if (task == null) return; //Are we running?
if (_cancelSource != null)
if (!_cancelSource.IsCancellationRequested && _cancelSource != null)
_cancelSource.Cancel();
}
return task;
await task;
}
public void SignalError(Exception ex)
{
lock (_lock)
using (_lock.Lock())
{
if (_stopReason != null) return;
@@ -130,33 +130,34 @@ namespace Discord
_cancelSource.Cancel();
}
}
public Task Error(Exception ex)
public async Task Error(Exception ex)
{
Task task;
lock (_lock)
using (await _lock.LockAsync())
{
if (_stopReason != null) return TaskHelper.CompletedTask;
if (_stopReason != null) return;
//Cache the task so we still have something to await if Cleanup is run really quickly
task = _task ?? TaskHelper.CompletedTask;
if (_cancelSource.IsCancellationRequested) return task;
_stopReason = ExceptionDispatchInfo.Capture(ex);
if (_cancelSource != null)
_cancelSource.Cancel();
if (!_cancelSource.IsCancellationRequested)
{
_stopReason = ExceptionDispatchInfo.Capture(ex);
if (_cancelSource != null)
_cancelSource.Cancel();
}
}
return task;
await task;
}
/// <summary> Throws an exception if one was captured. </summary>
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.