本文整理汇总了C#中AsyncOperation.ContinueWith方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncOperation.ContinueWith方法的具体用法?C# AsyncOperation.ContinueWith怎么用?C# AsyncOperation.ContinueWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncOperation
的用法示例。
在下文中一共展示了AsyncOperation.ContinueWith方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContinueWithActionInterfaceTest
public void ContinueWithActionInterfaceTest()
{
var operation = new AsyncOperation<bool>();
IOperationResult<bool> operationResult = OperationResult.CreateResult(OperationType.PageNavigation, this, true,
DataContext.Empty);
bool isInvoked = false;
var continuationAction = new ActionContinuationMock
{
Invoke = result =>
{
result.ShouldEqual(operationResult);
isInvoked = true;
}
};
operation.ContinueWith(continuationAction);
isInvoked.ShouldBeFalse();
operation.SetResult(operationResult);
isInvoked.ShouldBeTrue();
isInvoked = false;
operation.ContinueWith(continuationAction);
isInvoked.ShouldBeTrue();
}
示例2: OperationShouldSerializeAnonymousClassMethods
public void OperationShouldSerializeAnonymousClassMethods()
{
var vmMock = new NavigableViewModelMock();
ServiceProvider.OperationCallbackFactory = new SerializableOperationCallbackFactory(Serializer);
var operation = new AsyncOperation<bool>();
var result = OperationResult.CreateResult(OperationType.PageNavigation, this, true,
new NavigationContext(NavigationType.Page, NavigationMode.Back, vmMock, vmMock, this));
operation.ContinueWith(operationResult => CallbackAnonMethod(operationResult, vmMock));
ResultAnon.ShouldBeNull();
ViewModel.ShouldBeNull();
var callback = operation.ToOperationCallback();
var serialize = Serializer.Serialize(callback);
serialize.Position = 0;
callback = (IOperationCallback)Serializer.Deserialize(serialize);
IocContainer.GetFunc = (type, s, arg3) =>
{
if (type == GetType())
return this;
return Activator.CreateInstance(type);
};
ResultAnon.ShouldBeNull();
ViewModel.ShouldBeNull();
callback.Invoke(result);
ResultAnon.ShouldEqual(result);
ViewModel.ShouldEqual(vmMock);
}
示例3: OperationShouldSerializeStaticMethods
public void OperationShouldSerializeStaticMethods()
{
ServiceProvider.OperationCallbackFactory = new SerializableOperationCallbackFactory(Serializer);
var operation = new AsyncOperation<bool>();
var result = OperationResult.CreateResult(OperationType.PageNavigation, this, true);
operation.ContinueWith(operationResult => { ResultStatic = operationResult; });
ResultStatic.ShouldBeNull();
var callback = operation.ToOperationCallback();
var serialize = Serializer.Serialize(callback);
serialize.Position = 0;
callback = (IOperationCallback)Serializer.Deserialize(serialize);
ResultStatic.ShouldBeNull();
callback.Invoke(result);
ResultStatic.ShouldEqual(result);
}
示例4: OperationShouldSerializeInstanceMethods
public void OperationShouldSerializeInstanceMethods()
{
ServiceProvider.OperationCallbackFactory = new SerializableOperationCallbackFactory(Serializer);
var operation = new AsyncOperation<bool>();
var result = OperationResult.CreateResult(OperationType.PageNavigation, this, true);
operation.ContinueWith(CallbackMethod);
Result.ShouldBeNull();
var callback = operation.ToOperationCallback();
var serialize = Serializer.Serialize(callback);
serialize.Position = 0;
callback = (IOperationCallback)Serializer.Deserialize(serialize);
IocContainer.GetFunc = (type, s, arg3) =>
{
type.ShouldEqual(GetType());
return this;
};
Result.ShouldBeNull();
callback.Invoke(result);
Result.ShouldEqual(result);
}
示例5: ContinueWithActionInterfaceContinuationTest
public void ContinueWithActionInterfaceContinuationTest()
{
var operation = new AsyncOperation<bool>();
IOperationResult<bool> operationResult = OperationResult
.CreateResult(OperationType.PageNavigation, this, true, DataContext.Empty);
var exception = new TestException();
var continuationAction = new ActionContinuationMock
{
Invoke = result =>
{
throw exception;
}
};
var continueWith = operation.ContinueWith(continuationAction);
continueWith.IsCompleted.ShouldBeFalse();
operation.SetResult(operationResult);
continueWith.IsCompleted.ShouldBeTrue();
continueWith.Result.IsFaulted.ShouldBeTrue();
continueWith.Result.Exception.ShouldEqual(exception);
}
示例6: OperationShouldUseDelegateToConvertCallbackToSerializableDuringSerialization
public void OperationShouldUseDelegateToConvertCallbackToSerializableDuringSerialization()
{
var operation = new AsyncOperation<bool>();
var action = new Action<IOperationResult>(op => { });
var actionGeneric = new Action<IOperationResult<bool>>(op => { });
var func = new Func<IOperationResult, object>(op => null);
var funcGeneric = new Func<IOperationResult<object>, bool>(o => true);
var delegates = new List<Delegate> { action, actionGeneric, func, funcGeneric };
operation.ContinueWith(continuationFunction: func)
.ContinueWith(funcGeneric)
.ContinueWith(actionGeneric)
.ContinueWith(action);
OperationCallbackFactory.CreateSerializableCallback = @delegate =>
{
delegates.Remove(@delegate).ShouldBeTrue();
return new SerializableCallbackMock();
};
var operationCallback = operation.ToOperationCallback();
Serializer.Serialize(operationCallback);
delegates.ShouldBeEmpty();
}
示例7: OperationShouldUseDelegateToCreateMethodChainSerializableCallback
public void OperationShouldUseDelegateToCreateMethodChainSerializableCallback()
{
var operation = new AsyncOperation<bool>();
bool isFuncInvoked = false;
bool isFuncGenericInvoked = false;
bool isActionGenericInvoked = false;
bool isActionInvoked = false;
var func = new Func<IOperationResult, object>(op =>
{
isFuncInvoked = true;
return operation;
});
var funcGeneric = new Func<IOperationResult<object>, bool>(o =>
{
isFuncGenericInvoked = true;
o.Result.ShouldEqual(operation);
return true;
});
var actionGeneric = new Action<IOperationResult<bool>>(op =>
{
isActionGenericInvoked = true;
op.Result.ShouldBeTrue();
});
var action = new Action<IOperationResult>(op =>
{
isActionInvoked = true;
});
operation.ContinueWith(continuationFunction: func)
.ContinueWith(funcGeneric)
.ContinueWith(actionGeneric)
.ContinueWith(action);
OperationCallbackFactory.CreateSerializableCallback = @delegate =>
{
Func<IOperationResult, object> invoke = result => @delegate.DynamicInvoke(result);
return new SerializableCallbackMock() { Invoke = invoke };
};
operation.ToSerializableCallback()
.Invoke(OperationResult.CreateResult(OperationType.PageNavigation, this, true));
isFuncInvoked.ShouldBeTrue();
isFuncGenericInvoked.ShouldBeTrue();
isActionGenericInvoked.ShouldBeTrue();
isActionInvoked.ShouldBeTrue();
}
示例8: OperationShouldUseDelegateToCreateMethodChainOperationCallback
public void OperationShouldUseDelegateToCreateMethodChainOperationCallback()
{
var operation = new AsyncOperation<bool>();
bool isFuncInvoked = false;
bool isFuncGenericInvoked = false;
bool isActionGenericInvoked = false;
bool isActionInvoked = false;
var func = new Func<IOperationResult, object>(op =>
{
isFuncInvoked = true;
return operation;
});
var funcGeneric = new Func<IOperationResult<object>, bool>(o =>
{
isFuncGenericInvoked = true;
o.Result.ShouldEqual(operation);
return true;
});
var actionGeneric = new Action<IOperationResult<bool>>(op =>
{
isActionGenericInvoked = true;
op.Result.ShouldBeTrue();
});
var action = new Action<IOperationResult>(op =>
{
isActionInvoked = true;
});
operation.ContinueWith(continuationFunction: func)
.ContinueWith(funcGeneric)
.ContinueWith(actionGeneric)
.ContinueWith(action);
operation.ToOperationCallback()
.Invoke(OperationResult.CreateResult(OperationType.PageNavigation, this, true));
isFuncInvoked.ShouldBeTrue();
isFuncGenericInvoked.ShouldBeTrue();
isActionGenericInvoked.ShouldBeTrue();
isActionInvoked.ShouldBeTrue();
}
示例9: ContinueWithFunctionInterfaceGenericContinuationToOperationCallbackTest
public void ContinueWithFunctionInterfaceGenericContinuationToOperationCallbackTest()
{
var operation = new AsyncOperation<bool>();
IOperationResult<bool> operationResult = OperationResult
.CreateResult(OperationType.PageNavigation, this, true, DataContext.Empty);
var exception = new TestException();
var continuationFunction = new FunctionContinuationMock<bool, object>
{
Invoke = result =>
{
throw exception;
}
};
var continueWith = operation.ContinueWith(continuationFunction);
continueWith.IsCompleted.ShouldBeFalse();
operation.ToOperationCallback().Invoke(operationResult);
continueWith.IsCompleted.ShouldBeTrue();
continueWith.Result.IsFaulted.ShouldBeTrue();
continueWith.Result.Exception.ShouldEqual(exception);
}
示例10: ContinueWithFunctionInterfaceGenericToOperationCallbackTest
public void ContinueWithFunctionInterfaceGenericToOperationCallbackTest()
{
var operation = new AsyncOperation<bool>();
IOperationResult<bool> operationResult = OperationResult.CreateResult(OperationType.PageNavigation, this, true,
DataContext.Empty);
var funcResult = new object();
var continuationFunction = new FunctionContinuationMock<bool, object>
{
Invoke = result =>
{
result.ShouldEqual(operationResult);
return funcResult;
}
};
var op = operation.ContinueWith(continuationFunction);
op.IsCompleted.ShouldBeFalse();
operation.ToOperationCallback().Invoke(operationResult);
op.Result.Result.ShouldEqual(funcResult);
operation.ContinueWith(continuationFunction);
op.Result.Result.ShouldEqual(funcResult);
}