locked
Persistence of an Async Operation RRS feed

  • Question

  • If a process is started using Async\Await and then the main program is closed, does the Async process run to completion?  I can't find anything about this in the relevant documentation.  If you know where to look, please add a link.

    Add 1:

    The async process is moving a LOT of files so I don't care if the main program closes and the user goes on to other tasks as long as the file copying continues to completion.

    • Edited by RogerSSB Monday, October 28, 2019 11:20 PM
    Monday, October 28, 2019 2:06 PM

Answers

  • Karen, see my added info.  I am aware of the page you linked.
    Under normal operations the process mentioned will terminate. Not knowing all the facts best recommendation is to consider a) disallowing the application to terminate, allow it to be minimized b) only run the program when it's convenient for the user c) run off hours via Windows scheduler.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by RogerSSB Wednesday, October 30, 2019 6:09 PM
    Tuesday, October 29, 2019 11:33 AM

All replies

  • Hello,

    You should provide cancellation paths to ensure such a method might make data unstable. See the following documentation. So you should not let the app close without canceling async code.

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concepts/async/cancel-an-async-task-or-a-list-of-tasks  


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, October 28, 2019 2:45 PM
  • Karen, see my added info.  I am aware of the page you linked.
    Monday, October 28, 2019 11:21 PM
  • Hi

    Perhaps the easy way would be to Hide the main Form instead of Closing it - set a flag to indicate that the full Close should happen when Task is finished.


    Regards Les, Livingston, Scotland

    Monday, October 28, 2019 11:40 PM
  • If a process is started using Async\Await and then the main program is closed, does the Async process run to completion?  I can't find anything about this in the relevant documentation.  If you know where to look, please add a link.


    I think you have to search better. You cannot find exact documentation around your question. Because it is base knowledge around what is a task of a program. 

    Async in .Net is based on methods. A method ends as a program ends. (Maybe it is not direct released but the results become unusable). 

    https://en.wikipedia.org/wiki/Subroutine

    However, you are not the only one who mixes up threads with services. 


    Success
    Cor


    Tuesday, October 29, 2019 10:23 AM
  • Karen, see my added info.  I am aware of the page you linked.
    Under normal operations the process mentioned will terminate. Not knowing all the facts best recommendation is to consider a) disallowing the application to terminate, allow it to be minimized b) only run the program when it's convenient for the user c) run off hours via Windows scheduler.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by RogerSSB Wednesday, October 30, 2019 6:09 PM
    Tuesday, October 29, 2019 11:33 AM
  • Under normal operations the process mentioned will terminate.

    That's all I needed to know.  Thanks.

    Wednesday, October 30, 2019 6:09 PM