Background Agent - different between Abort() and NotifyComplete()

143 Views Asked by At

It's advised to call Abort() to notify the foreground app know that background was canceled intentionally. But how does the foreground app know that?

What's the actually different between Abort() and NotifyComplete()? Does anyone know this?

1

There are 1 best solutions below

1
On BEST ANSWER

Your BackgroundAgent should always call NotifyComplete or Abort. It informs the OS that it can free the resources and allocate them to other processes.

NotifyComplete means that the task has completed successfully and the agent will fire in the futere. Abort means that there was an error and agent won't be fired in the future unless you handle this in foreground app. More information you can find here at MSDN. There is also a good example:

The code for the agent is implemented by the application in a class that inherits from BackgroundAgent. When the agent is launched, the operating system calls OnInvoke(ScheduledTask). In this method, the application can determine which type of ScheduledTask it is being run as, and perform the appropriate actions. When the agent has completed its task, it should call NotifyComplete() or Abort() to let the operating system know that it has completed. NotifyComplete should be used if the task was successful. If the agent is unable to perform its task – such as a needed server being unavailable - the agent should call Abort, which causes the IsScheduled property to be set to false. The foreground application can check this property when it is running to determine whether Abort was called.

As it is said - in foreground app you can check ScheduledAction.IsScheduled, whether future invocations of the action are scheduled to occur (if it complited succesfully or failed).