Reading through the comments of another question, I see that there is risk of encountering race condition(s) when using the GetWindowThreadProcessId
Windows API method. How big of a risk is this?
Allow me to provide background into what I am attempting. I am writing a timekeeping app in C# for my own personal use. My intent was to have the app detect (via Win API calls) when the active window has changed so that I can log time against the application being used. I have already located code that detects when the active window changes; now I am trying to determine the process associated with that window. I have located several posts on SO that point to GetWindowThreadProcessId
as the solution, but as I mentioned there seems to be a potential issue in using it. If GetWindowThreadProcessId
is not a safe way to go, then I am open to other alternatives.
My hope was to keep the code wholly in C#, but I am not (completely) opposed to moving parts of it into C/C++ if necessary.
Thanks!