A class that wraps the Windows Restart Manager API to detect which processes are locking files and manage application restarts.
Methods
| Name |
|---|
| CreateSession |
| JoinSession |
| RegisterFile |
| RegisterFiles |
| IsResourcesLocked |
| GetProcessesLockingResources |
| Shutdown |
| Restart |
| Dispose |
| IsFileLocked |
| GetProcessesLockingFile |
Usage
This library provides functionality to interact with the Windows Restart Manager (RM) API, which helps identify processes that have locks on files and manage graceful shutdown and restart of applications.
Check if a File is Locked
The simplest way to check if a file is currently locked by any process:
1 |
|
Find Processes Locking a File
Get a list of all processes that have locks on a specific file:
1 | var path = @"C:\path\to\file.txt"; |
Manual Session Management
For more control, you can create and manage a Restart Manager session manually:
1 | // Create a new session |
Join an Existing Session
You can join an existing Restart Manager session using its session key:
1 | var sessionKey = "existing-session-key"; |
Shutdown and Restart Applications
The Restart Manager can shut down and restart applications that are locking resources:
1 | using var session = RestartManager.CreateSession(); |
Shutdown Types
The RestartManagerShutdownType enum provides options for how applications should be shut down:
ForceShutdown- Forces unresponsive applications and services to shut down after a timeout period (30 seconds for applications, 20 seconds for services)ShutdownOnlyRegistered- Only shuts down applications that have been registered for restart usingRegisterApplicationRestart. If any processes cannot be restarted, no shutdown occurs
Demo
you can run demo and see this feature.