CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Location
    .NET 3.5, VisualStudio-2008
    Posts
    30

    Event handler is being called more than once???

    Hi,

    I am using event-delegate pattern in the project to update the UI, when some data is received on the udp port. Each tabpage has 4 buttons on click of each button a request is sent to the device(h/w), based on the response received - respective event handler will be called.

    The problem is that the event handler is called twice, for the same request, which is not desired. Can someone tell me how this could be resolved???

    Any help would be great

  2. #2
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: Event handler is being called more than once???

    Can you post the relevant code using code tags?

  3. #3
    Join Date
    Apr 2010
    Posts
    131

    Re: Event handler is being called more than once???

    I agree with rohs -- need to see code for a speicfic solution. A generic (and not particulalry desireable) workaround might be:

    Code:
    bool hasBeenHandled = false;
    private void handlerMethod(){
       if(!hasBeenHandled){
            //do your stuff
            hasBeenHandled=true;
       }else{
           hasBeenHandled = false;
       }
    }
    This will ensure that the method ignores every other time it's called.
    Again, not the best workaround, but without knowing what's going on, this is a rough patch. Post your code for more detailed answer =)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured