How do i properly stop windows service?

0

I have created a windows service, and I have the following OnStop method in my "service" class:

protected override void OnStop()
    {
        Logger.Info("Stopping service");
        Program.Service.Stop();
    }

And my Program.Service.Stop looks like this:

public static Service Service;

public static void Stop()
    {
        if (Service != null)
            Service.Stop();
        else
            Environment.Exit(0);
    }

This creates an event error for some reason:

Faulting application name: Updater.exe, version: 1.0.0.0, time stamp: 0xcfc2ec12
Faulting module name: RPCRT4.dll, version: 10.0.19041.746, time stamp: 0xf564aeb4
Exception code: 0xc00000fd
Fault offset: 0x00000000000441b0
Faulting process id: 0x4698
Faulting application start time: 0x01d6ef1029d43301
Faulting application path: C:\Program Files\YouMo\Service\Updater.exe
Faulting module path: C:\WINDOWS\System32\RPCRT4.dll
Report Id: ad53a0e5-47d8-4462-9bc4-7eaf13746b93
Faulting package full name: 
Faulting package-relative application ID: 

When I uncomment the Program.Service.Stop method call, I don't get the error because the service keeps running. So I know the error is triggered by the stop method, but I don't know how to fix it.

c#
service
windows-services
asked on Stack Overflow Jan 20, 2021 by Benji • edited Jan 20, 2021 by Benji

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0