0
votes

I have a UWP application that needs to perform a log task for every system start/resume/suspend/shutdown.

Is there a way I could do this task with a background task? From the MS documents, there seems to be no sort of trigger for such events.

I currently have a service that does this, and access to the service from the UWP could be performed, but the service will not be packaged along with the UWP app so it might not be the best solution right now.

1
you can catch the start/resume/suspend/shutdown event in app.xaml.cs file so you just need to create a service through which you can add current application log - user11362349
you can refer this link in which you can see the UWP application life cycle. for launch you just need to copy the OnLaunched event from given link and paste it to app.xaml.cs file.now call your service in OnLaunched event which can add the application launch state to database. do same for other events. - user11362349
@ketan I understand that this lifecycle is meant for the UWP app itself. But what I want to listen to are more of system power events (i.e. shutdown the computer, put it to sleep, etc...) - Jer Yango
As you said, there seems to be no sort of trigger for such events, so if you want to achieve through the background task, it is not feasible. - Faywang - MSFT

1 Answers

0
votes

Im not sure about what you asking for but if you just want to execute background task you can use :

using System.Threading;

namespace yourNamespace
{
    static class Program
    {
        static void main()
        {
            Thread thread = new thread(Task);
            thread.Start();
        }

        private void Task()
        {
            //What you want to do
        }
    }
}