Today we open sourced our process management library, Warden. It aims to simplify tracking processes and their children across Windows. For this development blog we wanted to dive into why we needed to create this library.
Understanding the Core Problem
With Rainway we are tasked with launching thousands of different applications from various third parties. In a perfect scenario an application is launched via its executable and nothing else occurs. It is in this scenario the .NET Process API is sufficient, however the issue is that this is rarely the case.
Using Warden we can get a visual representation of how your average game launches:
A Warden process tree
As you can see in the above image the world of Windows processes is live fast and die fast. The process that actually spawned the game died quickly and it’s impossible to know that information using Process.GetProcesses if you aren’t constantly querying it. So now you have an orphaned game processes and you can’t know the grandparents of each child process, so you’re left with a fragmented process tree.
Taking advantage of WMI we can subscribe to some different events: Win32_ProcessStartTrace and Win32_ProcessStopTrace. Using these events we can know know when processes on the machine have stopped and started without polling. Polling uses unnecessary CPU time and from our initial implementations can miss when processes have actually started.
When a new process has been detected we do a top down scan of process tree to determine where it fits. The same method occurs for when a process exits.
The goal was to remain as close to the Process class as possible; however, Warden can manage many types of launches: Win32, UWP and URI. While both Process and Warden are asynchronous, Warden can wait asynchronously for a process to start. This gives you a reliable way to know if your action was performed.
You can also build a tree from an already active process and begin monitoring it.
Deep process tree scanning
We hope this library helps other developers out there and now that it is open source, become more fleshed out to fit the needs of the many.
You can contribute on Github and find more documentation on how to get started using Warden in your application: Click Here
Rainway will be released November 25th, don’t forget to sign up for the beta here.
Thanks for reading!