

HANDLE g_ServiceStopEvent = INVALID_HANDLE_VALUE SERVICE_STATUS_HANDLE g_StatusHandle = NULL spawn an isolate that does the actual work It must also be the Dart Application to that needs to call Init(.) using Dart FFI. Windows Services, it it the Dart Application of enabling Dart applications to run as Because this was developed for the purpose application either before or after the call to Init(.). do any work, but keep the Windows Service The functions in this file don't actually the latter from the indefinite wait and terminating ServiceMain(.) function, essentially freeing close request by setting the event created by the The ServiceCtrlHandler(.) function responds to a Creates an event object that and then waits indefinitely are only handling the request to stop the service). tasked to handle control requests (in this case we as the service control handler, which is essentially Registers the ServiceCtrlHandler(.) function the ServiceMain function does the following: function as the actual windows service function. The Init(.) function registers the ServiceMain(.) The entry point to this API is the Init(.) integrate themselves as Windows Services Provides an API for Dart console applications to Here's the full code of the Service.c file: I grabbed Mohit's code and made a ton of changes (including backporting it to C, because. However, there are 2 things we can use: Dart:FFI, and the following article from Mohit Arora that explains how to create a Windows Service in C++.

I don't think there is a pub package available to perform this duty. If this isn't done, Windows service gets stuck in a "Starting state". The issue with sc.exe create is that the main function of the application needs to perform some extra steps to inform Windows that it is running. I am compiling the dart application as an executable and then registering it as a Windows Service, using sc.exe create. My solution is kind of an hack, but hey, it works. I am arriving really late to the game, but I figured a way around this problem without having to use 3rd party applications. So, the simple solution is, we don't really need to run Dart code as a Windows Service, because we can run it as a docker container on the server. To test this out, Windows 10 supports Docker with Windows containers. On the server you will need docker and you can simply run the image with a -restart option. Instead of actually running the application as a Windows Service, the alternative is to compile it to an executable Windows console application, create a Docker file and a Windows Docker image that will include that application. However, none of this is really needed as a much, much, simpler solution can be had by using Docker with Windows Containers. My original answer consisted of using C and Dart FFI to boostrap the Windows Service.
