Event Order

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter

    #1

    Event Order

    Hi,

    I have two different methods that need to be executed when one event is
    raised. The general way I've done this is to attach the same handle to both
    methods, as follows.

    Public Sub Method1 (ByVal sender as Object, ByVal e as EventArgs) Handles
    Control.Event1
    'code
    End Sub

    Public Sub Method2 (ByVal sender as Object, ByVal e as EventArgs) Handles
    Control.Event1
    'code
    End Sub

    But I need to ensure that Method1 is executed before Method2. How can I do
    this? I thought that changing their order in code would work --- and it did
    in one instance --- but in another, Method2 is executed first. How does
    VB.NET decide what order it does these things in?

  • Andrew Taylor

    #2
    Re: Event Order

    Why not just call the two methods you want to execute as Subs
    from a single event handler?



    On 28 May, 16:57, "Peter" <star...@hotmai l.comwrote:
    Hi,
    >
    I have two different methods that need to be executed when one event is
    raised. The general way I've done this is to attach the same handle to both
    methods, as follows.
    >
    Public Sub Method1 (ByVal sender as Object, ByVal e as EventArgs) Handles
    Control.Event1
    'code
    End Sub
    >
    Public Sub Method2 (ByVal sender as Object, ByVal e as EventArgs) Handles
    Control.Event1
    'code
    End Sub
    >
    But I need to ensure that Method1 is executed before Method2. How can I do
    this? I thought that changing their order in code would work --- and it did
    in one instance --- but in another, Method2 is executed first. How does
    VB.NET decide what order it does these things in?

    Comment

    • Miro

      #3
      Re: Event Order

      I have read in the doc's that the "Order" of which multiple events for the
      same "handles" is unknown.

      I would create 2 subs - and call them one after the other properly.

      M.

      "Peter" <starrim@hotmai l.comwrote in message
      news:uZC6i.1429 5$Ut6.7410@news read1.news.pas. earthlink.net.. .
      Hi,
      >
      I have two different methods that need to be executed when one event is
      raised. The general way I've done this is to attach the same handle to
      both methods, as follows.
      >
      Public Sub Method1 (ByVal sender as Object, ByVal e as EventArgs) Handles
      Control.Event1
      'code
      End Sub
      >
      Public Sub Method2 (ByVal sender as Object, ByVal e as EventArgs) Handles
      Control.Event1
      'code
      End Sub
      >
      But I need to ensure that Method1 is executed before Method2. How can I do
      this? I thought that changing their order in code would work --- and it
      did in one instance --- but in another, Method2 is executed first. How
      does VB.NET decide what order it does these things in?

      Comment

      • Peter

        #4
        Re: Event Order

        That might work... I might have to do some fancy select cases for it though,
        as in my actual code, one method has about 25 handlers attached to it, but
        each of the handlers is also individually attached to one of 25 subs. I was
        thinking of maybe calling the second method from the first.

        "Andrew Taylor" <andrew.taylor@ cantab.netwrote in message
        news:1180370482 .160358.84710@p 47g2000hsd.goog legroups.com...
        Why not just call the two methods you want to execute as Subs
        from a single event handler?
        >
        >
        >
        On 28 May, 16:57, "Peter" <star...@hotmai l.comwrote:
        >Hi,
        >>
        >I have two different methods that need to be executed when one event is
        >raised. The general way I've done this is to attach the same handle to
        >both
        >methods, as follows.
        >>
        >Public Sub Method1 (ByVal sender as Object, ByVal e as EventArgs) Handles
        >Control.Even t1
        > 'code
        >End Sub
        >>
        >Public Sub Method2 (ByVal sender as Object, ByVal e as EventArgs) Handles
        >Control.Even t1
        > 'code
        >End Sub
        >>
        >But I need to ensure that Method1 is executed before Method2. How can I
        >do
        >this? I thought that changing their order in code would work --- and it
        >did
        >in one instance --- but in another, Method2 is executed first. How does
        >VB.NET decide what order it does these things in?
        >
        >

        Comment

        Working...