本文整理汇总了C#中System.Threading.Tasks.TaskCompletionSource.SetResult方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Tasks.TaskCompletionSource.SetResult方法的具体用法?C# System.Threading.Tasks.TaskCompletionSource.SetResult怎么用?C# System.Threading.Tasks.TaskCompletionSource.SetResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.TaskCompletionSource
的用法示例。
在下文中一共展示了System.Threading.Tasks.TaskCompletionSource.SetResult方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoginAsync
public static System.Threading.Tasks.Task LoginAsync(string username, string password)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<PTPrincipal>();
PTIdentity.GetPTIdentity(username, password, (o, e) =>
{
if (e.Error == null && e.Object != null)
{
SetPrincipal(e.Object);
tcs.SetResult(null);
}
else
{
Logout();
if (e.Error != null)
tcs.SetException(e.Error.InnerException);
else
tcs.SetCanceled();
}
});
return tcs.Task;
}
示例2: Delay
/// <summary>
/// Task.Delayが.NET 4だと搭載されていないので擬似関数作成
/// </summary>
/// <param name="milliseconds"></param>
private void Delay(int milliseconds)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<object>();
new System.Threading.Timer(_ => tcs.SetResult(null)).Change(milliseconds, -1);
tcs.Task.Wait();
}
示例3: FadeToBlackAsync
private System.Threading.Tasks.Task FadeToBlackAsync()
{
CallFadeOut.Visibility = Visibility.Visible;
var tcs = new System.Threading.Tasks.TaskCompletionSource<object>();
EventHandler<object> completed = null;
completed = (o, e) =>
{
FadeToBlack.Completed -= completed;
tcs.SetResult(null);
};
FadeToBlack.Completed += completed;
FadeToBlack.Begin();
return tcs.Task;
}
示例4: GetInitialUrlAsync
public async override System.Threading.Tasks.Task<Uri> GetInitialUrlAsync()
{
// just return if no replacement requested
if (string.IsNullOrEmpty(replacementUrlFormat))
return await base.GetInitialUrlAsync();
// get base class Uri
System.Diagnostics.Debug.WriteLine("GetUriFromTaskUri: replacementUrlFormat:" + replacementUrlFormat);
Uri uri = await base.GetInitialUrlAsync();
System.Diagnostics.Debug.WriteLine("GetUriFromTaskUri: base.uri:" + uri);
// need to extract state query string from base Uri because its scope isn't public.
string baseUrl = uri.OriginalString;
int stateIndex = baseUrl.LastIndexOf("&state=");
string requestState = baseUrl.Substring(stateIndex + "&state=".Length);
// verify that the base Url is same as our supposedly identical procedure. If not, there must be a code change in a new version of base class.
string redoUrl = string.Format(
"{0}?client_id={1}&redirect_uri={2}&response_type={3}&scope={4}&state={5}",
AuthorizeUrl.AbsoluteUri,
Uri.EscapeDataString(ClientId),
Uri.EscapeDataString(RedirectUrl.AbsoluteUri),
AccessTokenUrl == null ? "token" : "code",
Uri.EscapeDataString(Scope),
Uri.EscapeDataString(requestState));
if (baseUrl != redoUrl)
throw new ArgumentException("GetInitialUrlAsync: Url comparison failure: base: " + baseUrl + " redo:" + redoUrl);
// format replacement Uri
uri = new Uri(string.Format(
replacementUrlFormat,
AuthorizeUrl.AbsoluteUri,
Uri.EscapeDataString(ClientId),
Uri.EscapeDataString(RedirectUrl.AbsoluteUri),
AccessTokenUrl == null ? "token" : "code",
Uri.EscapeDataString(Scope),
Uri.EscapeDataString(requestState)));
System.Diagnostics.Debug.WriteLine("GetUriFromTaskUri: replacement uri:" + uri);
System.Threading.Tasks.TaskCompletionSource<Uri> tcs = new System.Threading.Tasks.TaskCompletionSource<Uri>();
tcs.SetResult(uri);
return uri;
}
示例5: GetResponseAsync
public System.Threading.Tasks.Task<IResponse> GetResponseAsync(System.Threading.CancellationToken cancellationToken)
{
System.Threading.Tasks.TaskCompletionSource<IResponse> tcs = new System.Threading.Tasks.TaskCompletionSource<IResponse>();
tcs.SetResult(new ResponseImpl(xrequest.GetResponseAsync(cancellationToken)));
return tcs.Task;
}
示例6: RequestTimeAsync
/// <summary>
/// Returns an awaitable task whose result is the current time from the NTP server specified in the constructor.
/// </summary>
/// <remarks>
/// <para>This method may throw exceptions (most likely a <seealso cref="NtpNetworkException"/> if an error occurs trying to connect/bind to the network endpoint. Exception handling in client code is recommended.</para>
/// </remarks>
/// <seealso cref="NtpNetworkException"/>
public System.Threading.Tasks.Task<DateTime> RequestTimeAsync()
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<DateTime>();
var client = new NtpClient(_ServerAddress);
var timeReceivedHandler = new EventHandler<NtpTimeReceivedEventArgs>(
(sender, args) =>
{
tcs.SetResult(args.CurrentTime);
}
);
var errorOccurredHandler = new EventHandler<NtpNetworkErrorEventArgs>(
(sender, args) =>
{
if (!tcs.Task.IsCanceled && !tcs.Task.IsCompleted)
tcs.SetException(args.Exception);
}
);
client.TimeReceived += timeReceivedHandler;
client.ErrorOccurred += errorOccurredHandler;
var retVal = tcs.Task;
tcs.Task.ContinueWith(
(pt) =>
{
client.TimeReceived -= timeReceivedHandler;
client.ErrorOccurred -= errorOccurredHandler;
}
);
client.BeginRequestTime();
return retVal;
}
示例7: GetAccessTokenAsync
public virtual System.Threading.Tasks.Task<TwitterAsyncResult<OAuthAccessToken>> GetAccessTokenAsync(OAuthRequestToken requestToken, string verifier)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<TwitterAsyncResult<OAuthAccessToken>>();
GetAccessToken(requestToken, verifier,
(token, response) =>
{
tcs.SetResult(new TwitterAsyncResult<OAuthAccessToken>(token, response));
}
);
return tcs.Task;
}
示例8: GetAccessTokenWithXAuthAsync
public virtual System.Threading.Tasks.Task<TwitterAsyncResult<OAuthAccessToken>> GetAccessTokenWithXAuthAsync(string username, string password)
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<TwitterAsyncResult<OAuthAccessToken>>();
GetAccessTokenWithXAuth(username, password, (token, response) =>
{
tcs.SetResult(new TwitterAsyncResult<OAuthAccessToken>(token, response));
});
return tcs.Task;
}
示例9: GetRequestTokenAsync
public virtual System.Threading.Tasks.Task<TwitterAsyncResult<OAuthRequestToken>> GetRequestTokenAsync()
{
var tcs = new System.Threading.Tasks.TaskCompletionSource<TwitterAsyncResult<OAuthRequestToken>>();
GetRequestToken((token, response) =>
{
tcs.SetResult(new TwitterAsyncResult<OAuthRequestToken>(token, response));
});
return tcs.Task;
}
示例10: Main
/// <summary>
/// Service main entry point
/// </summary>
/// <param name="args">
/// Startup parameters
/// </param>
public static void Main(string[] args)
{
// preset logger
var loggerConfig = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.ColoredConsole();
var logger = loggerConfig.CreateLogger();
Log.Logger = logger;
var arguments = new Docopt().Apply(CommandUsage, args, exit: true);
var configurations = new List<string>();
ValueObject config;
if (arguments.TryGetValue("--config", out config) && config != null)
{
configurations.Add(config.ToString());
}
Container = new WindsorContainer();
AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
{
Log.Logger.Error(
eventArgs.ExceptionObject as Exception,
"{Type}: Unhandled domain exception from {SenderType}, terminating: {IsTerminating}\n{StackTrace}",
"System",
sender?.GetType().Name ?? "unknown",
eventArgs.IsTerminating,
(eventArgs.ExceptionObject as Exception)?.StackTrace);
};
var system = Bootstrapper.ConfigureAndStart(Container, configurations.ToArray());
Log.Logger.Warning("{Type}: Started", "System");
Console.CancelKeyPress += (sender, eventArgs) =>
{
Log.Logger.Warning("{Type}: Shutdown sequence initiated", "System");
var cluster = Akka.Cluster.Cluster.Get(system);
var timeout = TimeSpan.FromSeconds(10);
if (cluster.IsTerminated || cluster.State.Members.Count == 0)
{
system.Terminate().Wait(timeout);
}
else
{
cluster.LeaveAsync().Wait(timeout);
system.Terminate().Wait(timeout);
}
Log.Logger.Warning("{Type}: Hard stopped", "System");
eventArgs.Cancel = true;
};
system.StartNameSpaceActorsFromConfiguration();
BaseInstaller.RunPostStart(Container);
var waitedTask = new System.Threading.Tasks.TaskCompletionSource<bool>();
system.WhenTerminated.ContinueWith(task => waitedTask.SetResult(true));
waitedTask.Task.Wait();
Log.Logger.Warning("{Type}: Stopped", "System");
}