views:

64

answers:

2

Hi Folks

Not sure if i will be able to formulate my question quite clear but let me try:

So i've written a small piece of code which will give the user the option to select a desired status for his Office Communicator when his PC get locked ( by default it goes automatically on status "away" ) .So here it is the Windows Form wich is basically a combobox and a button .The Combo has four option "Away" , "Busy" , Do not Disturb" and "Online" respectively. All seems fine and the program compiles ok.The Menu appears , you select the status you wish , push the button and then lock your PC - so far all goes perfect.Your Status is as selected .And now comes the Problem.You unlock your PC and try to select a different status , same actions , but when you lock the PC it still shows the previously selected status here is the Button_Click method

public void Btn_Click(Object sender, EventArgs e)
{
    // When the button is clicked,
    // change the button text, and disable it.     
    if (Comb.Text == "Away")
    {    
        MessageBox.Show("Saved ! \nYour Status will be 'Away' ");
        Method2();
    }

    else if (Comb.Text == "Busy")
    {       
        MessageBox.Show("Saved ! \nYour Status will be  'Busy' ");
        Method1();    
    }

    else if (Comb.Text == "Do Not Disturb")
    {
        MessageBox.Show("Saved ! \nYour Status will be 'Do Not Disturb' ");
        Method3();
    }

    else
    {   
        MessageBox.Show("Saved ! \nYour Status will be 'Online' ");
        Method4();
    }

    But.Enabled = true;
    // Display the greeting label text.
}

So the 4 methods ( Method1 () , 2 ... etc ) are the one to change the status depending on the text in the combo box drop down menu ( the status you select )i have tested all methods separately from each other and they work beautiful thereforfe i exclude a problems with them , is it some logical error ?

A: 

static void SystemEvents_SessionSwitch1(object sender, SessionSwitchEventArgs e)

    {

        if (e.Reason == SessionSwitchReason.SessionLock)


        {
         System.Threading.Thread.Sleep(500);
         CommunicatorAPI.MessengerClass comm=new  CommunicatorAPI.MessengerClass();

         if(comm.MyStatus==MISTATUS.MISTATUS_AWAY)

         {


                       SetMyPresence1 ();
         }

          else if (e.Reason == SessionSwitchReason.SessionUnlock)

        {

         ChangeStatus1 ();

        }
        }
Nikolay
What happens within SetMyPresence1()? This is presumably where the status is supposed to change...
Mark Avenius
Hi Mark , SetMyPresence is basically where the status is changed its quite straightforward and i have tested it many times before that so i don't expect the issue to come from this line
Nikolay
A: 

Nikolay, give SharpDevelop's debugger a try. In your code's margin click once next to the line if (Comb.Text == "Away") and then hover over the variable names to see what they are set to each time it runs. You can use the "Step over" "Step into" and "Step out" functions to "Execute the highlighted method without looking at the internals", "Debug the Internals of a method" or "Run the current method to the end and then show the next level up" respectively.

If you do this you'll figure out why you're getting an error and it will be MUCH easier to determine where the error is coming from. (For instance, if a variable is set to an unexpected value you'll know to figure out when that changed).

Cpfohl