pub fn single_instance(app_id: &str) -> Result<Option<InstanceGuard>>Expand description
Attempts to acquire a named process-wide single-instance guard.
Returns Ok(Some(InstanceGuard)) for the first instance and Ok(None) if another
instance with the same app_id is already running.
Examples found in repository?
examples/single_instance.rs (line 2)
1fn main() {
2 match win_desktop_utils::single_instance("demo-app").unwrap() {
3 Some(_guard) => {
4 println!("first instance");
5 println!("press Enter to exit");
6 let mut s = String::new();
7 std::io::stdin().read_line(&mut s).unwrap();
8 }
9 None => {
10 println!("already running");
11 }
12 }
13}