I have an async method:
public async Task DoSomethingAsync(){ ... await ... await ... .... return await SaveAsync(); }
In most cases, I call this method:
await DoSomethingAsync()
This call works as expected. But somewhere I have to call this method fire and forget:
public void OtherMethod() { ... DoSomethingAsync();
In this case, Task DoSomethingAsync() sometimes starts and ends, but sometimes the task is never called (or calls some await inside DoSomethingAsync() , but never completes the last await SaveAsync(); ).
I try to make sure that the task will be called into the fire and forget this code:
public void OtherMethod() { ... Task.Factory.StartNew(() => { await DoSomethingAsync(); }); //fire and forget again here }
However, this does not work as an expectation. So my questions are:
How to make a DoSomethingAsync() call without await always execute and end? (I don't care what the reboot / AppDomain crashes)
If I delete all the async/await code inside DoSomethingAsync() and replace await with .ContinueWith() , then the call to Task DoSomethingAsync() (does not have async in the method declaration) will be called and sure to complete (ignore the AppDomain restart / crash case) , if so, how long is the call (I donβt think I will be happy if Task is called in 10 minutes)?
source share