2

i have a else loop where two methods are executing,

static private void HandleClientStateCB(string clientName, 
                                     SPD.SPD_clientStateType state, object pb){
     //IF()
     else {
         HandlePCAEvent(myDevice, SpoServer.PCA.Event.DeviceInactive, "");
         HandlePCAEvent(myDevice, SpoServer.PCA.Event.DeviceDisconnect, "");
     }
}

what my requirement was whenever client disconnected that time i need to make version to null.The existing condition is like this

static private void HandleClientEventCB(SPD.SPD_eventType type, 
                          SPD.SPD_event this_event, object passback){
    //------------------
    string agentVersion = "0.0.0.0";
    if (this_event.variableData.Length >= 6 ){
         agentVersion = this_event.variableData[5].atr_value;
    }
}

So what i did is i declared a boolean variable test private static bool test = false; then i used in else loop

static private void HandleClientStateCB(string clientName, 
                                    SPD.SPD_clientStateType state, object pb){
    //IF()
    else {
        HandlePCAEvent(myDevice, SpoServer.PCA.Event.DeviceInactive, "");
        HandlePCAEvent(myDevice, SpoServer.PCA.Event.DeviceDisconnect, "");
        test = true;
    }
}

static private void HandleClientEventCB(SPD.SPD_eventType type, 
                                     SPD.SPD_event this_event, object passback){
    //-------------------------------
    string agentVersion = "0.0.0.0";
    if (this_event.variableData.Length >= 6 && test==false ){
        agentVersion = this_event.variableData[5].atr_value;
    }
}

But this logic is not working,Can any body suggest any other logic so that disconnect time my version should be Null

1
  • 1
    code-formatting really exists and is not a unicorn. Commented Dec 16, 2010 at 5:50

1 Answer 1

1

How do you check that device is disconnected when you set test = true;? If that condition is available in HandleClientEventCB function just check it again. Else you need to pass true/false to HandleClientEventCB to know if device is disconnected.

As an aside don't you use different events for DeviceActive, DeviceInactive, DeviceConnect and DeviceDisconnect. If yes then you can know if HandleClientEventCB is being called for disconnect or not.

Sign up to request clarification or add additional context in comments.

2 Comments

eventtype 'DeviceDisconnect' will make sure disconnect event happen,so what i did is after that i used boolean variable to 'true' in HandleClientStateCB and passed to HandleClientEventCB
won't SPD.SPD_eventType tell you which event is this. Then you can check it in HandleClientEventCB function and set agentVersion to null if it is DeviceDisconnect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.