Is there a way to use TaskContinuationOptions like a finally?
Here is my code
ShowLoading();
Task.Factory.StartNew((Action)(() =>
{
_broker.SetDrugDataFromAPI(newDrug);
})).ContinueWith(x =>
{
lock (this)
{
//Do Something to UI
}
}, _uiScheduler).ContinueWith(x =>
{
//Do Somehting after change UI
}).ContinueWith(x =>
{
HideLoading();
}, TaskContinuationOptions.OnlyOnFaulted);
Here is my question
I wanted to use last ContinueWith like a finally. So, I changed my last ContinueWith phrase like this
}).ContinueWith(x =>
{
HideLoading();
}, TaskContinuationOptions.OnlyOnRanToCompletion |
TaskContinuationOptions.OnlyOnFaulted);
I thought it be used when the last task is complete or fault.
But It throws a error.
I hope there is a good way to solve my problem.
thank you for reading my question.