Crates.io | winsrv |
lib.rs | winsrv |
version | 0.0.1 |
source | src |
created_at | 2024-06-19 03:57:47.014227 |
updated_at | 2024-06-19 03:57:47.014227 |
description | Simple implementation of windows service |
homepage | |
repository | https://github.com/zsaw/winsrv-rs |
max_upload_size | |
id | 1276482 |
size | 7,719 |
Simple implementation of windows service
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);
}
This project is licensed under the MIT license.