本文整理汇总了C#中System.Threading.CancellationTokenSource.Wait方法的典型用法代码示例。如果您正苦于以下问题:C# CancellationTokenSource.Wait方法的具体用法?C# CancellationTokenSource.Wait怎么用?C# CancellationTokenSource.Wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.CancellationTokenSource
的用法示例。
在下文中一共展示了CancellationTokenSource.Wait方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeCutAsync
public async Task InvokeCutAsync()
{
_sentCutToken = new CancellationTokenSource();
_ahkEngine.ExecRaw("SendInput ^x\nRun,Pastr.Messaging.exe sentcut");
await _sentCutToken.Wait();
}
示例2: InvokePasteAsync
public async Task InvokePasteAsync()
{
_sentPasteToken = new CancellationTokenSource();
_ahkEngine.ExecRaw("SendInput ^v\nRun,Pastr.Messaging.exe sentpaste");
await _sentPasteToken.Wait();
}
示例3: ConnectInternal
public async Task<string> ConnectInternal(string emailOrUsername, string password, string token)
{
bool success = false;
await Disconnect();
_blockEvent.Reset();
_disconnectToken = new CancellationTokenSource();
string url = (await _api.GetWebSocket()).Url;
if (token != null)
{
try
{
//Login using cached token
await _webSocket.ConnectAsync(url);
if (_isDebugMode)
RaiseOnDebugMessage(DebugMessageType.Connection, $"DataSocket connected.");
_http.Token = token;
await _webSocket.Login(_http.Token);
if (_isDebugMode)
RaiseOnDebugMessage(DebugMessageType.Connection, $"DataSocket got token.");
success = true;
}
catch (InvalidOperationException) //Bad Token
{
if (_isDebugMode)
RaiseOnDebugMessage(DebugMessageType.Connection, $"DataSocket had a bad token.");
if (password == null) //If we don't have an alternate login, throw this error
throw;
}
}
if (!success)
{
//Open websocket while we wait for login response
Task socketTask = _webSocket.ConnectAsync(url);
if (password != null) //Normal Login
{
var response = await _api.Login(emailOrUsername, password);
if (_isDebugMode)
RaiseOnDebugMessage(DebugMessageType.Connection, $"DataSocket got token.");
token = response.Token;
}
else //Anonymous login
{
var response = await _api.LoginAnonymous(emailOrUsername);
if (_isDebugMode)
RaiseOnDebugMessage(DebugMessageType.Connection, $"DataSocket generated anonymous token.");
token = response.Token;
}
_http.Token = token;
//Wait for websocket to finish connecting, then send token
await socketTask;
if (_isDebugMode)
RaiseOnDebugMessage(DebugMessageType.Connection, $"DataSocket connected.");
await _webSocket.Login(_http.Token);
if (_isDebugMode)
RaiseOnDebugMessage(DebugMessageType.Connection, $"DataSocket logged in.");
success = true;
}
if (success)
{
if (_config.UseMessageQueue)
_mainTask = MessageQueueLoop();
else
_mainTask = _disconnectToken.Wait();
_mainTask = _mainTask.ContinueWith(async x =>
{
await _webSocket.DisconnectAsync();
#if !DNXCORE50
if (_config.EnableVoice)
await _voiceWebSocket.DisconnectAsync();
#endif
//Clear send queue
Message ignored;
while (_pendingMessages.TryDequeue(out ignored)) { }
_channels.Clear();
_messages.Clear();
_roles.Clear();
_servers.Clear();
_users.Clear();
_blockEvent.Set();
_mainTask = null;
}).Unwrap();
_isConnected = true;
}
else
token = null;
return token;
}