I have case:
Screen1 opens Dialog1, then Dialog1 opens Dialog2, then Dialog2 either returns result to Dialog1 or closes Screen1
Due to technical reasons I want to open each dialog like here (it's pseudo-code, shows idea):
// somewhere in screen1
var dialog1_result = await dialog1.ShowDialogAndAskUser();
// somewhere in dialog1
var dialog2_result = await dialog2.ShowDialogAndAskUser();
But sometimes Dialog2 can close the whole Screen1 and above awaits aren't needed any more.
// somewhere in dialog2
screen1.CloseScreenAndAllDialogs();
Can I leave above awaits on dialog1_result, dialog2_result?
Will GC clean it? (assuming that instances of screen1, dialog1-2 are GC-ed)
these tasks are not really abandoned because they are awaited. The question in your case should actually be "What will happen with an uncompleted asynchronous operation?". And the answer is that this code will never be GCed unless the asynchronous method is finished completely (with or without exception). There's not enough info for us to say for sure. Everything depends on what CloseScreenAndAllDialogs does. If ShowDialogAndAskUser async method is never completed explicitly by someone then it will live and wait forever - compiler just cannot finish it for you.
This is very hard to answer in the general case, because it comes down to is the task still reachable from the thing that is going to say "here's your result"? - and we can't answer that. Is dialog1 still alive, for example? if dialog1 is still reachable and alive, and the task is still incomplete, then dialog1_result will still be reachable and alive - because there is a reference chain in place to allow the result to be set at some future time. The converse is not true, however; the task should not keep the dialog alive (unless someone has used async-state in some unusual way).