本文整理汇总了C#中Task.OnSuccess方法的典型用法代码示例。如果您正苦于以下问题:C# Task.OnSuccess方法的具体用法?C# Task.OnSuccess怎么用?C# Task.OnSuccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Task
的用法示例。
在下文中一共展示了Task.OnSuccess方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpgradeToRevocableSessionAsync
internal Task UpgradeToRevocableSessionAsync(Task toAwait, CancellationToken cancellationToken) {
string sessionToken = SessionToken;
return toAwait.OnSuccess(_ => {
return ParseSession.UpgradeToRevocableSessionAsync(sessionToken, cancellationToken);
}).Unwrap().OnSuccess(t => {
return SetSessionTokenAsync(t.Result);
}).Unwrap();
}
示例2: SaveAsync
private Task SaveAsync(Task toAwait, IProgress<AVUploadProgressEventArgs> progress,
CancellationToken cancellationToken)
{
lock (this.mutex)
{
string currentSessionToken = AVUser.CurrentSessionToken;
}
long position = this.dataStream.Position;
return toAwait.OnSuccess<Task>(t => {
Task task1 = null;
lock (this.mutex)
{
if (!this.IsDirty)
{
task1 = Task.FromResult<int>(0);
}
else
{
string str = Guid.NewGuid().ToString();
str = string.Concat(str, Path.GetExtension(this.name));
task1 = this.GetQiniuToken(str, cancellationToken).ContinueWith(s => {
this.MergeFromJSON(s.Result.Item2);
return this.ResumableUploadToQiniu(progress, str, cancellationToken);
}, cancellationToken).Unwrap().ContinueWith<Task>(d => {
Task task = null;
task = (d.Result.Item1 == HttpStatusCode.OK ? Task.FromResult<int>(0) : this.DeleteAsync(cancellationToken));
return task;
}, cancellationToken).Unwrap();
}
}
return task1;
}).Unwrap().ContinueWith<Task>((Task t) => {
if ((t.IsFaulted || t.IsCanceled) && this.dataStream.CanSeek)
{
this.dataStream.Seek(position, SeekOrigin.Begin);
}
return t;
}, cancellationToken).Unwrap();
}
示例3: SignUpAsync
internal Task SignUpAsync(Task toAwait, CancellationToken cancellationToken) {
if (AuthData == null) {
// TODO (hallucinogen): make an Extension of Task to create Task with exception/canceled.
if (string.IsNullOrEmpty(Username)) {
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
tcs.TrySetException(new InvalidOperationException("Cannot sign up user with an empty name."));
return tcs.Task;
}
if (string.IsNullOrEmpty(Password)) {
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
tcs.TrySetException(new InvalidOperationException("Cannot sign up user with an empty password."));
return tcs.Task;
}
}
if (!string.IsNullOrEmpty(ObjectId)) {
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
tcs.TrySetException(new InvalidOperationException("Cannot sign up a user that already exists."));
return tcs.Task;
}
IDictionary<string, IParseFieldOperation> currentOperations = StartSave();
return toAwait.OnSuccess(_ => {
return UserController.SignUpAsync(State, currentOperations, cancellationToken);
}).Unwrap().ContinueWith(t => {
if (t.IsFaulted || t.IsCanceled) {
HandleFailedSave(currentOperations);
} else {
var serverState = t.Result;
HandleSave(serverState);
}
return t;
}).Unwrap().OnSuccess(_ => SaveCurrentUserAsync(this)).Unwrap();
}
示例4: DeleteAsync
internal Task DeleteAsync(Task toAwait, CancellationToken cancellationToken)
{
if (ObjectId == null)
{
return Task.FromResult(0);
}
string sessionToken = AVUser.CurrentSessionToken;
return toAwait.OnSuccess(_ =>
{
return FileController.DeleteAsync(state, sessionToken, cancellationToken);
}).Unwrap().OnSuccess(_ => { });
}