本文整理汇总了C#中System.Threading.Tasks.Task.ConfigureAwait方法的典型用法代码示例。如果您正苦于以下问题:C# Task.ConfigureAwait方法的具体用法?C# Task.ConfigureAwait怎么用?C# Task.ConfigureAwait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.Task
的用法示例。
在下文中一共展示了Task.ConfigureAwait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryWithUacFallback
public async Task<bool> TryWithUacFallback(Task task, string info) {
if (!Tools.Processes.Uac.CheckUac()) {
await task.ConfigureAwait(false);
return false;
}
Exception e;
try {
await task.ConfigureAwait(false);
return false;
} catch (UnauthorizedAccessException ex) {
e = ex;
}
var report = await _dialogManager.MessageBoxAsync(new MessageBoxDialogParams(
String.Format(
"The application failed to write to the path, probably indicating permission issues\nWould you like to restart the application Elevated?\n\n {0}\n{1}",
info, e.Message),
"Restart the application elevated?", SixMessageBoxButton.YesNo)) == SixMessageBoxResult.Yes;
UsageCounter.ReportUsage("Dialog - Restart the application elevated: {0}".FormatWith(report));
if (!report)
throw e;
RestartWithUacInclEnvironmentCommandLine();
return true;
}
示例2: TryWithUacFallback
public async Task<bool> TryWithUacFallback(Task task, string info) {
if (!Tools.UacHelper.CheckUac()) {
await task.ConfigureAwait(false);
return false;
}
Exception e;
try {
await task.ConfigureAwait(false);
return false;
} catch (UnauthorizedAccessException ex) {
e = ex;
}
var report =
await
_dialogManager.MessageBox(
new MessageBoxDialogParams(
$"The application failed to write to the path, probably indicating permission issues\nWould you like to restart the application Elevated?\n\n {info}\n{e.Message}",
"Restart the application elevated?", SixMessageBoxButton.YesNo)).ConfigureAwait(false) ==
SixMessageBoxResult.Yes;
if (!report)
throw e;
RestartWithUacInclEnvironmentCommandLine();
return true;
}
示例3: Do
public async Task Do(Action act, TaskScheduler scheduler = null)
{
Exception lastException = null;
int retryCount = -1;
TimeSpan wait;
while (true)
{
try
{
var task = new Task(act);
task.Start(scheduler);
await task.ConfigureAwait(false);
break;
}
catch (OutOfMemoryException)
{
throw;
}
catch (Exception ex)
{
lastException = ex;
}
retryCount++;
if (!GetShouldRetry(retryCount, lastException, out wait))
{
ExceptionDispatchInfo.Capture(lastException).Throw();
}
else
{
await Task.Delay(wait).ConfigureAwait(false);
}
}
}
示例4: PostStart
public async Task PostStart(IBus bus, Task<BusReady> busReady)
{
if (_log.IsDebugEnabled)
_log.DebugFormat("Job Service Starting: {0}", _jobService.InputAddress);
await busReady.ConfigureAwait(false);
if (_log.IsInfoEnabled)
_log.InfoFormat("Job Service Started: {0}", _jobService.InputAddress);
}
示例5: Callback
private static async Task Callback(Task<WebResponse> task, WebRequest request)
{
try
{
var response = await task.ConfigureAwait(false);
}
catch (WebException)
{
}
}
示例6: GetRequestStreamCallback
private async Task GetRequestStreamCallback(Task<Stream> task, HttpWebRequest request)
{
Stream postStream = await task.ConfigureAwait(false);
this.WriteMultipartObject(postStream, this.Parameters);
postStream.Close();
var responseTask = request.GetResponseAsync();
await GetResponseCallback(responseTask);
}
示例7: DebugPrintAnalyticsOutput
private async void DebugPrintAnalyticsOutput(Task<string> resultTask, Dictionary<string, string> hitData)
{
using (var form = new FormUrlEncodedContent(hitData))
{
var result = await resultTask.ConfigureAwait(false);
var formData = await form.ReadAsStringAsync().ConfigureAwait(false);
Debug.WriteLine($"Request: POST {_serverUrl} Data: {formData}");
Debug.WriteLine($"Output of analytics: {result}");
}
}
示例8: AuthenticateAsync
/// <summary>
/// Authenticate using the secret for the specified client from the key store
/// </summary>
/// <param name="clientId">The active directory client id for the application.</param>
/// <param name="audience">The intended audience for authentication</param>
/// <param name="context">The AD AuthenticationContext to use</param>
/// <returns></returns>
public async Task<AuthenticationResult> AuthenticateAsync(string clientId, string audience, AuthenticationContext context)
{
var task = new Task<SecureString>(() =>
{
return ServicePrincipalKeyStore.GetKey(clientId, _tenantId);
});
task.Start();
var key = await task.ConfigureAwait(false);
return await context.AcquireTokenAsync(audience, new ClientCredential(clientId, key));
}
示例9: DoWithoutSleepAsync
/// <summary>
/// Awaits the given task without having the device going to sleep.
/// </summary>
/// <returns>A task to await.</returns>
/// <param name="action">Task to run.</param>
/// <param name="task">Task.</param>
public async Task DoWithoutSleepAsync(Task task)
{
try
{
ActivateAutoSleepMode(false);
await task.ConfigureAwait(false);
}
finally
{
ActivateAutoSleepMode(true);
}
}
示例10: PostStart
public async Task PostStart(IBus bus, Task<BusReady> busReady)
{
if (_log.IsDebugEnabled)
_log.DebugFormat("Quartz Scheduler Starting: {0} ({1}/{2})", _schedulerEndpointAddress, _scheduler.SchedulerName, _scheduler.SchedulerInstanceId);
await busReady.ConfigureAwait(false);
_scheduler.JobFactory = new MassTransitJobFactory(bus);
_scheduler.Start();
if (_log.IsInfoEnabled)
_log.InfoFormat("Quartz Scheduler Started: {0} ({1}/{2})", _schedulerEndpointAddress, _scheduler.SchedulerName, _scheduler.SchedulerInstanceId);
}
示例11: AuthenticateAsync
/// <summary>
/// Authenticate using certificate thumbprint from the datastore
/// </summary>
/// <param name="clientId">The active directory client id for the application.</param>
/// <param name="audience">The intended audience for authentication</param>
/// <param name="context">The AD AuthenticationContext to use</param>
/// <returns></returns>
public async Task<AuthenticationResult> AuthenticateAsync(string clientId, string audience, AuthenticationContext context)
{
var task = new Task<X509Certificate2>(() =>
{
return AzureSession.DataStore.GetCertificate(this._certificateThumbprint);
});
task.Start();
var certificate = await task.ConfigureAwait(false);
return await context.AcquireTokenAsync(
audience,
new ClientAssertionCertificate(clientId, certificate));
}
示例12: StartMonitoring
public async void StartMonitoring(Task preTask)
{
LogHelper.Logger.InfoFormat("{0} A ring is set up: {1}", m_host.FullName, DisplayName);
await preTask.ConfigureAwait(false);
LogHelper.Logger.InfoFormat("{0} Ring pretask done. Starting check loop for {1}", m_host.FullName, DisplayName);
while (true)
{
await Task.Delay(m_host.m_dataflowOptions.MonitorInterval).ConfigureAwait(false);
bool empty = false;
if (m_hb.NoHeartbeatDuring(() => { empty = this.IsRingEmpty(); }) && empty)
{
LogHelper.Logger.DebugFormat("{0} 1st level empty ring check passed for {1}", m_host.FullName, this.DisplayName);
bool noHeartbeat = await m_hb.NoHeartbeatDuring(
async () =>
{
//trigger batch
foreach (var batchedFlow in m_ringNodes.OfType<IBatchedDataflow>())
{
batchedFlow.TriggerBatch();
}
await Task.Delay(m_host.m_dataflowOptions.MonitorInterval).ConfigureAwait(false);
empty = this.IsRingEmpty();
}).ConfigureAwait(false);
if (noHeartbeat && empty)
{
LogHelper.Logger.DebugFormat("{0} 2nd level empty ring check passed for {1}", m_host.FullName, this.DisplayName);
m_hb.Complete(); //start the completion domino :)
break;
}
else
{
//batched flow dumped some hidden elements to the flow, go back to the loop
LogHelper.Logger.DebugFormat("{0} New elements entered the ring by batched flows ({1}). Will fall back to 1st level empty ring check.", m_host.FullName, this.DisplayName);
}
}
}
LogHelper.Logger.InfoFormat("{0} Ring completion detected! Completion triggered on heartbeat node: {1}", m_host.FullName, DisplayName);
}
示例13: GetClientResponseAsync
private async Task<ClientResponse> GetClientResponseAsync(Task<HttpResponseMessage> responseTask)
{
// get the response
HttpResponseMessage response = await responseTask.ConfigureAwait(false);
// get the content
HttpContent httpContent = response.Content;
byte[] content = await httpContent.ReadAsByteArrayAsync().ConfigureAwait(false);
// construct the output
return new ClientResponse
{
Content = content,
Headers = response.Headers,
StatusCode = response.StatusCode
};
}
示例14: OnGetResponseCompleted
private async Task OnGetResponseCompleted(Task<WebResponse> task)
{
if (this._isCancelled)
{
return;
}
// get the response
HttpWebResponse response;
try
{
response = (HttpWebResponse)await task.ConfigureAwait(false);
}
catch (Exception e)
{
this.InvokeOnErrorHandler(ErrorMessages.WebPageLoadError);
return;
}
if (response.StatusCode != HttpStatusCode.OK)
{
this.InvokeOnErrorHandler((int)response.StatusCode + " " + response.StatusDescription);
return;
}
// response stream
Stream stream;
if (this.OnProgressChanged != null && response.Headers.AllKeys.Any(key => key == "Content-Length"))
{
var progressStream = new ProgressStream(response.GetResponseStream(), response.ContentLength);
progressStream.OnProgressChanged = v => this.InvokeInUiThread(() => this.OnProgressChanged(v));
stream = progressStream;
}
else
{
stream = response.GetResponseStream();
}
if (!this._isCancelled)
{
this.OnStreamDownloaded(stream);
}
}
示例15: GetResponseCallback
private async Task GetResponseCallback(Task<WebResponse> task)
{
// get the response
HttpWebResponse response;
try
{
response = (HttpWebResponse)await task.ConfigureAwait(false);
}
catch (Exception e)
{
if (e.InnerException != null && e.InnerException.Message.StartsWith("[net_WebHeaderInvalidControlChars]"))
{
// not an exception, everything is ok
this.InvokeInUiThread(() => this.OnCompleted(null));
}
else
{
this.InvokeOnErrorHandler(ErrorMessages.HttpPostError);
}
return;
}
if (response.StatusCode != HttpStatusCode.OK)
{
this.InvokeOnErrorHandler((int)response.StatusCode + " " + response.StatusDescription);
return;
}
// response stream
using (Stream stream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream))
{
string str = reader.ReadToEnd();
this.InvokeInUiThread(() => this.OnCompleted(str));
}
}
}