mainprashant89
mainprashant89

Reputation: 77

Long-running task performed in foreground is suspended when app goes to background

When a user first opens my app, I need to download and install some content from a server before they can begin using the app. The problem is that this takes around 5 minutes on wifi, during which time the app goes into the background and the download is suspended.

Is there any way to either:

Prevent an windows app from entering the background while I perform my download or continue peforming the task in the background (i.e. perform the task irrespective of whether the app is in the foreground or background)

Also, I don't want to use the BackgroundDownloadManager

Thanks

Upvotes: 0

Views: 210

Answers (1)

Romasz
Romasz

Reputation: 29792

When the app is being suspended, all processes are stopped and and background task cancelled. Your last chance to do something is Suspending event - see more at MSDN.

In your case, when you need to download big file in the background - the mentioned BackgroundDownloader would be the best option - it's designed for such tasks. In other cases you will have to convince user to leave the app in the foreground (a message?), also take care about lockscreen (see DisplayRequest class).

I'm not also sure but maybe you will be able to use BackgroundTask (separate process), triggered with MaintanceTrigger - but then user will be able to download the file only in specific circumstances and probably not right away.

Upvotes: 1

Related Questions