I'm creating an UWP application with a background task. I don't want to run the background when the real application is running or suspended. Is there some way to achieve that? I’ve looked on SystemConditionType but nothing fits what I'm looking for.
相关问题
- Inheritance impossible in Windows Runtime Componen
- How can I overwrite a file in UWP?
- UWP - MessageDialog crashes the app on Windows Pho
- Reading the response from HttpClient.GetStringAsyn
- UsbDevice.FromIdAsync returns null
相关文章
- Show flyout using BottomAppBar
- Could not find a suitable SDK to target
- await Task.CompletedTask for what?
- How can i create Flashlight app in uwp C#
- VisualStateManager for UI Responsive is not workin
- Xamarin Form - How To checked the checkbox on anot
- How to create draggable pin in windows 10 to give
- Event Handlers not working with inkCanvas in Windo
Since background tasks (except special ones) run in a separate process, there is not an elegant way to check if app is running or not since memory is not shared between the app and the background task. There are two ways that I implemented successfully:
App Service
Create an app service in the app, in the background task, try to connect to the service. If service is available, it means that the app is running. This is the favorite one when you need communication between the task and the app.
File Lock
This is the favorite one in simple scenarios that you just need to know if the app is running or not.
Note: In the new API that is available in anniversary update, background tasks may be executed in the same process as the app. Using the new model, you won't have this problem anymore.