, , .
, . , , :
, Windows Forms. P/Invoke , Mutex:
(, GUID)
Mutex, .
EnumWindows P/Invoke .
EnumWindows GetProp P/Invoke , . GetProp (.. ), (PostMessage (... SC_RESTORE...), SetForegroundWindow, SetFocus), .
, SetProp P/Invoke, .
.
In my use case, this solution is better than just saving the mutex for the lifetime of the process, because it makes it possible to activate the previous instance if the user starts the second instance, and not just leaves it. Using GetProp / SetProp gives you a way to identify a process instance without relying on the process name.
source
share