Registers a delegate to be invoked on completion of the task.
The delegate will be invoked with the
TResult result as parameter.Do not use in conjunction with any other methods (await or calling
GetResult).Note: If the task throws an exception during execution, there is no way to catch it in when using
ContinueWith. Most
Meta XR Core SDK calls that return an
OVRTask do not throw, but it is possible to return an
OVRTask<TResult> from your own async method, which can still throw. For example,
async OVRTask\<OVRAnchor\> DoSomethingAsync() {
var anchor = await OVRAnchor.CreateSpatialAnchorAsync(pose); // doesn't throw
thrownew Exception(); // Cannot be caught if using ContinueWith
return anchor;
}
async void MethodA() {
try {
var anchor = await DoSomethingAsync();
} catch (Exception e) {
// okay; exception caught!
}
}
void MethodB() {
DoSomethingAsync().ContinueWith(anchor =\> {
Debug.Log($"Anchor {anchor} created!");
});
}
In the above example, the exception generated by DoSomethingAsync is caught in MethodA, but there is no way to catch it in MethodB because it uses
ContinueWith rather than await. The exception is still thrown, however.
ParametersonCompletedA delegate to be invoked when this task completes. If the task is already complete, onCompleted is invoked immediately.
ExceptionsArgumentNullExceptionThrown if onCompleted is null.
InvalidOperationExceptionThrown if this task is already being awaited.
InvalidOperationExceptionThrown if this task is already used in another
ContinueWith.
InvalidOperationExceptionThrown if this task is already used as a ValueTask (
ToValueTask).
InvalidOperationExceptionThrown if this task is already used or as an Awaitable. (ToAwaitable, only available in Unity 2023.1+).