I have a constructor that calls Task.Run()as follows:
public MyPage() {
Task.Run(() => {
MyHeavyCpuMethod();
});
}
Here MyPage()is the constructor of the UI component, and I donβt want it to MyHeavyCpuMethod()run in my user interface thread, so I unload it using Task.Run()fire-and-forget mode, since I donβt care when it finishes MyHeavyCpuMethod().
However, in this way, if it MyHeavyCpuMethod()throws, I cannot handle the exception that is in the returned Task.
How can I do error handling in this case?
source
share