none
SessionChangeReason.RemoteDisconnect and SessionChangeReason.RemoteConnect windows Events are fired twice on disconnect and reconnect of the machine RRS feed

  • Question

  • Hi Every one,

    I have developed a windows application in which i am capturing the windows events like lock,unlock, logon,disconnect etc.

    I have written the following code in windows service for capturing the events as they occured.

      protected override void OnSessionChange(SessionChangeDescription changeDescription)
            {
                string pcName = Environment.MachineName.ToUpper();
               System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                    System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "MMM dd yyyy";
                    System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern = "hh:mm:ss tt";
                    System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.DateSeparator = "/";
                    switch (changeDescription.Reason)
                    {
                         
                        case SessionChangeReason.SessionLock:
                            Idlog("4800");
                            Eventlogs(pcName, "4800", "System locked", DateTime.Now);
                            break;
                        case SessionChangeReason.SessionLogoff:
                            Eventlogs(pcName, "4647", "System logoff", DateTime.Now);
                            break;
                        case SessionChangeReason.SessionLogon:
                            Idlog("4624");
                            Eventlogs(pcName, "4624", "System logon", DateTime.Now);
                            break;
                        case SessionChangeReason.SessionUnlock:
                            Idlog("4801");
                            Eventlogs(pcName, "4801", "System Unlocked", DateTime.Now);
                            break;
                        case SessionChangeReason.RemoteDisconnect:
                            Eventlogs(pcName, "4779", "Session disconnected", DateTime.Now);
                            break;
                        case SessionChangeReason.RemoteConnect:
                            //LogEntry("Remote connect at {0}=" + DateTime.Now.AddMilliseconds(DateTime.Now.Millisecond));
                            Idlog("4778");
                            Eventlogs(pcName, "4778", "Session reconnected", DateTime.Now);
                            break;
                        case SessionChangeReason.ConsoleConnect:
                            // LogEntry("console connect at {0}=" + DateTime.Now.AddMilliseconds(DateTime.Now.Millisecond));
                            Idlog("4778");
                            Eventlogs(pcName, "4778", "Session c reconnected", DateTime.Now);
                            break;
                        case SessionChangeReason.ConsoleDisconnect:
                            //LogEntry("console disconnect at {0}=" + DateTime.Now.AddMilliseconds(DateTime.Now.Millisecond));
                            Eventlogs(pcName, "4779", "Session c disconnecetd", DateTime.Now);
                            break;
                        default:
                            break;
    
                    }
                //}
            }

    Everything is working fine but the 

    SessionChangeReason.RemoteConnect and SessionChangeReason.RemoteDisconnect are being fired two times always when i perform Disconnect and Reconnect

    and the order is as follows

    <tfoot></tfoot>

    Message
    Session disconnected
    Session reconnected
    Session disconnected
    Session reconnected

    So for two events iam getting four results.

    Can anybody please help me why this is happening?

    Thanks in Advance

    • Moved by Sabah ShariqMVP Thursday, September 15, 2016 11:33 AM Related to WCF
    Thursday, September 8, 2016 5:59 AM

Answers

  • Hi ananth,

    I made some more tests, and it seems my suppose is wrong. If I connect the remote, close remote dialog, reconnect with credential, and only log the four records.

    If you want to check how many times the user login by remote, what I could think out is group by the records every four records since one remote login will follow reconnect, disconnect, reconnect and eventually disconnect.

    If you want to check the status of remote user, I think you could add a variable to control the status, you could refer the link below:

    #SessionChangeReason Enumeration

    https://msdn.microsoft.com/en-us/library/system.serviceprocess.sessionchangereason(v=vs.110).aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Monday, September 19, 2016 10:32 AM

All replies

  • Hi ananth46.reddy

    Thanks for posting there.

    It seems related to the order of operation thread . when you use override ,is a new thread which perform Disconnect and Reconnect in superclass? May be the new thread has a time delay , thus when you call method in sub class, the thread in superclass has finished and thrown the event result . you could rewrite your the output in your subclass and tested the new output. 

    If you have anything else , please feel free to let me know.

    Best regards

    Kevin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    • Edited by Kevin Linq Friday, September 9, 2016 4:17 PM
    Friday, September 9, 2016 4:15 PM
  • Hi Kevin,

    Thanks for the response and sorry for the delay in replay

    what do you mean by "rewrite your the output in your subclass" ? can you please elaborate it more.

    And also please check the timing of occurence of the events below.

    <tfoot></tfoot>
    Eventlogs
    Message
    date_col
    Session c disconnecetd
    9/15/2016 11:38:31 AM
    Session c reconnected
    9/15/2016 11:38:32 AM
    Session c disconnecetd 9/15/2016 11:40:26 AM
    Session c reconnected
    9/15/2016 11:40:26 AM

    I have Disconnected at 11:38:31AM and reconnected at 11:40:26AM. But as you can see timings of occurence in the above table its clear that on disconnect event both 'disconnect & Reconnect' are called and also on reconnect both 'disconnect & Reconnect' are called how can this happen in any way?

    Regards

    Ananth


    Thursday, September 15, 2016 4:33 AM
  • Hi ananth,

    Could you please "Debug" through switch/ case statements to check why the code in being called twice?

    Also as your issue is related to WCF and this is Visual C# forum, I am moving your post to WCF forum for getting quick response.

    Thanks,

    Sabah Shariq

    Thursday, September 15, 2016 11:32 AM
  • Hi ananth46,

    Thanks for your post.

    I made a test based on your description, and I could reproduce your issue.

    In my option, after disconnecting remote, “SessionChangeReason.RemoteDisconnect” fires. While you reconnect remote, the first time local will send session without credential, so the session will fail, and then the session disconnected. After you enter credential in remote window, it will reconnect successfully.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, September 16, 2016 6:09 AM
  • Hi Edward,

    For

    SessionChangeReason.ConsoleConnect and 
    SessionChangeReason.ConsoleDisconnect 

    Also iam facing the same issue

    what can be the solution for this?

    Thanks,

    ananth

    Friday, September 16, 2016 11:20 AM
  • Hi ananth,

    I made some more tests, and it seems my suppose is wrong. If I connect the remote, close remote dialog, reconnect with credential, and only log the four records.

    If you want to check how many times the user login by remote, what I could think out is group by the records every four records since one remote login will follow reconnect, disconnect, reconnect and eventually disconnect.

    If you want to check the status of remote user, I think you could add a variable to control the status, you could refer the link below:

    #SessionChangeReason Enumeration

    https://msdn.microsoft.com/en-us/library/system.serviceprocess.sessionchangereason(v=vs.110).aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Monday, September 19, 2016 10:32 AM