winsrv

Crates.iowinsrv
lib.rswinsrv
version0.0.1
sourcesrc
created_at2024-06-19 03:57:47.014227
updated_at2024-06-19 03:57:47.014227
descriptionSimple implementation of windows service
homepage
repositoryhttps://github.com/zsaw/winsrv-rs
max_upload_size
id1276482
size7,719
(zsaw)

documentation

README

Winsrv

Simple implementation of windows service

Example

On Cargo.toml:

[dependencies]
winsrv = { version = "0.0.1" }

Then, on your main.rs:

use std::sync::mpsc::{Receiver, RecvTimeoutError::Disconnected};
use std::time::Duration;
use winsrv::{run_service, SERVICE_CONTROL_SHUTDOWN, SERVICE_CONTROL_STOP};

fn srvmain(receiver: Receiver<u32>) {
    loop {
        match receiver.recv_timeout(Duration::from_secs(1)) {
            Ok(ctl) => match ctl {
                SERVICE_CONTROL_STOP | SERVICE_CONTROL_SHUTDOWN => break,
                _ => continue,
            },
            Err(err) => {
                if err == Disconnected {
                    break;
                }
            }
        };

        // Your code ...
    }
}

fn main() {
    run_service("Demo", srvmain);
}

License

This project is licensed under the MIT license.

Commit count: 2

cargo fmt