HiddenWindow
A lightweight .NET library that enables console applications to receive and respond to Windows messages, particularly the TaskKill signal, by creating a hidden window with an associated message loop.
HiddenWindow solves a common challenge in Windows console applications: the inability to gracefully handle termination signals like TaskKill. By creating a hidden window with a Windows message loop, this library allows your console application to intercept and respond to these signals before the application is forcefully terminated.
This is particularly useful for applications that need to perform cleanup operations, save state, or notify other services before shutting down. Without HiddenWindow, a TaskKill command would immediately terminate your application without any opportunity to respond.
The library is designed to be simple to use with minimal overhead, making it an ideal solution for any .NET console application that requires graceful shutdown capabilities.
Install the package via NuGet:
dotnet add package HiddenWindow
Add the following code to your console application:
using HiddenWindow;
class Program
{
static void Main(string[] args)
{
// Register an event handler for the close signal
HiddenWindow.OnClose += (message) =>
{
Console.WriteLine("Application is shutting down...");
// Perform cleanup operations here
};
// Create the hidden window
HiddenWindow.Create();
// Your application code continues here
Console.WriteLine("Application is running. Press Ctrl+C to exit.");
// Keep the application running
Console.ReadLine();
}
}
HiddenWindow creates an invisible window with a Windows message loop that intercepts system messages. When a TaskKill signal is received, the library raises the OnClose
event, allowing your application to perform any necessary cleanup before termination.
We welcome contributions to HiddenWindow! Whether you're fixing a bug, adding a feature, or improving documentation, your help is greatly appreciated.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
For more detailed contribution guidelines, please see our CONTRIBUTING.md.
Please see our security policy for details on reporting security vulnerabilities.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.