Handling power events in .net core

Viewed 245

Can someone help me with alternative way for handling power events in .net core?

I am porting my .net framework window service applications to .net core 2.2, and in .net framework I was using ServiceBase class and itself methods for handling power events (OnPowerEvent). I want to handle events such as Suspend, Resume, etc.

Now I am using HostBuilder for hosting windows service and I couldn't find any solution for getting system power events.

1 Answers

You can use Worker Services. It has a StartAsync and StopAsync virtual method that you can override.

I advise you to upgrade to .NET Core 3.x because older versions won't be supported any more:

enter image description here

Related