vendredi 27 février 2015

Why does System.Diagnostic.Process throw exception when switching apps using windows tas kbar icon?

I'm currently developing an app that uses System.Diagnostics.Process to get the Window Title of the Current Active App or the App on the ForeGround. Now, this is fine and working with the current code I have until I came across with this issue. This NullReferenceException occurs if I switch my app using the task bar icon instead of the minimized button of the app window.


enter image description here


enter image description here


Originally I used this



[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();


To get what I need. But I'm still having the same issue when switching app using the task bar icon. The only difference with using this code is that the exception is this A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll


My operating system is Windows 8.1.


Any inputs is greatly appreciated.


Best regards


Aucun commentaire:

Enregistrer un commentaire