CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2011
    Posts
    69

    Exclamation How do I use a timer and a numericUpDown?

    Hi I was wondering how do I use a timer and a numericUpDown that specifies the amount of seconds?

    I just need the timer to make my program not do anything for a few seconds (but not freeze the interface) so I assume I wouldnt need to use the timer_tick event.

    Do you guys know how to do this?

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How do I use a timer and a numericUpDown?

    The timer will not do what you seem to be wanting. A timer fires an event every x milliseconds. Other objects continue to run as usual. To make to program stop for a period of time you would need to use the Sleep method of the Threading class.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Sep 2011
    Posts
    69

    Re: How do I use a timer and a numericUpDown?

    I tried this but it doesnt seem to be waiting the amount of time I specify in the numericUpDown:

    Code:
    timer1.Interval = Convert.ToInt32(numericUpDown2.Value * 1000);
    timer1.Start();

  4. #4
    Join Date
    Sep 2011
    Posts
    69

    Re: How do I use a timer and a numericUpDown?

    I am testing this with a webBrowser, and want it to stop doing anything for the specified amount of time but even with the timer on, nothing stops

  5. #5
    Join Date
    Sep 2011
    Posts
    69

    Re: How do I use a timer and a numericUpDown?

    Bump...........

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How do I use a timer and a numericUpDown?

    As I said a timer does not stop execution of your program. A timer fires an event every x milliseconds. If you wanted something to happen say in 30 seconds you could use a timer and place the code in the timer 30 seconds after the timer is enabled the code would execute. Other code will execute as it normally would timer will have no effect. To halt execution of code you must use Sleep. You can use a loop to keep code from going on but that is not always such a good idea.

    A timer will not do what you wish.
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Sep 2011
    Posts
    69

    Re: How do I use a timer and a numericUpDown?

    Oh , thanks for clearing that up.

    Also, doesnt sleep freeze the whole gui?

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How do I use a timer and a numericUpDown?

    Sleep freezes the thread that it is called on. If it is called on the GUI thread then yes it will freeze the GUI
    Always use [code][/code] tags when posting code.

Tags for this Thread

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