Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VB.NET event driven routines

Options
  • 30-10-2011 3:22am
    #1
    Closed Accounts Posts: 1,155 ✭✭✭


    Hi all,

    Very quick question:

    In VB.NET, let's say I have one module that is kicked off by Button1.Click. I also have another module that is started by Timer1.Tick.

    Hypothetically, if the timer ticks at the exact same time as the button is pressed, will my modules run on different threads?

    Or do I need to code it to run multi-threaded?

    Thanks!


Comments

  • Registered Users Posts: 2,149 ✭✭✭dazberry


    Windows GUI is single threaded and uses a messaging system (WM_CLICK, WM_TIMER etc.), so the two events will never happen at the same time. The messages will be queued and one will happen before the other.

    Also if for instance the button click is queued first, and the timer is triggered second, the timer event will not run until the button event code completes. If your button click takes 10 seconds the UI will appear frozen until the event completes (unless you process windows messages as part of the event).

    HTH

    D.


  • Closed Accounts Posts: 1,155 ✭✭✭Stainless_Steel


    OK great thanks.

    So say if I had a timer with an interval of 2 seconds. If the code driven by the timers tick takes longer than 2 seconds what happens? Will I get a crash or will the next timer tick be ignored?


  • Registered Users Posts: 2,149 ✭✭✭dazberry


    Off the top of my head I'm not sure, nothing to test it on now, but I know it won't crash or the event re-fire (reentrant), I think the next tick will just be ignored.

    D.


Advertisement