2014-07-17 18 views
2

當用戶切換到另一個用戶時,我需要關閉串口並終止應用程序。當用戶切換到另一個用戶時可以處理嗎?交換機用戶處理系統事件

這是我的代碼,我可以處理當用戶註銷但切換用戶時無法處理。

static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e) 
{ 
    switch (e.Reason) 
    { 
     case SessionEndReasons.Logoff: 
      serialPort1.Close(); 
      Process.GetCurrentProcess().Kill(); 
      break; 

     //Here i want handle process for switch user 
     //case SessiondEndReasons.SwitchUser?? 
     //  serialPort1.Close(); 
     //  Process.GetCurrentProcess().Kill(); 
     //  break; 
    } 
} 

回答