0

Having spent the last several days converting a working frontend application for a database with Async/Await, I fear I have worked myself into a corner. Being new to all this, I have a very simple question.

What happens to an "awaiting" process when the computer is suspended? Additionally, can a process that is "awaiting" be detected in a generic fashion so that the user can be warned that "the process is not finished" prior to Window closure? (The application has many Create and Update processes to manage the database backend).

TIA

Alan Wayne
  • 5,122
  • 10
  • 52
  • 95
  • Thanks to @F.Koenig, found discussion at http://stackoverflow.com/questions/5562969/what-happens-when-a-task-is-running-and-its-window-is-closed to be particularly useful. – Alan Wayne Jun 08 '16 at 16:05

1 Answers1

1

Instead of

await DoAsync();

you could do something like

task = DoAsync();
await task;

and when closing your application, you might want to check somewhere else

if(task.Status == TaskStatus.Running)
    ...

this would make sense for long running operations. Have a look at the Task Class, though.

F.Koenig
  • 128
  • 4
  • Anyway to detect implicitly if any task is running? (Each Windows has many async operations). Thanks. – Alan Wayne Jun 08 '16 at 15:49
  • By default, no. A custom TaskScheduler could eventually provide such functionality, but I am sure there are easier and more elegant ways to solve your Problem. I would consider a design where long running operations are encapsulated in a way that allows you to react upon their status. The Task-class itself also provides various methods to deal with multiple instances of tasks, such as Task.WaitAll, Task.WaitAny and so forth... – F.Koenig Jun 13 '16 at 14:47