locked
windows forms timer tick event RRS feed

  • Question

  • Hi

    I am trying to set up a windows form based application.I am using vc++ express edition.

    In the form I added a timer and set the interval to 1(Means 1 msec). And in the Tick event I am doing my pjt specific functionality,

    To make sure I am getting the tick event at every 1 msec i intialised a counter and updated it in the functionality after it reaches 1000 i set it to 1 again and printed the output using lable in the windows form.

    To my surprise I am getting the update for every 15 secs.. which means i am not getting tick event for every 1 msec. instead i am getting delayed events.

    Please let me know if I am missing any settings..

    Followiing is the code I am using..

     

    void

     

    InitializeComponent(void

    )

    {

    .....

    ....

    

     

    this->tSystemTick->Enabled = true;

     

    this->tSystemTick->Interval = 1;

     

    this->tSystemTick->Tick += gcnew System::EventHandler(this, &Form1::tSystemTick_Tick);

     

     

    //

    ........

    }

    

    private

    : System::Void tSystemTick_Tick(System::Object^ sender, System::EventArgs^ e)

    {

    u32Counter++;

     

     

     

    if

    (u32Counter > 1000)

    {

    u32Counter = 0;

    u32Seconds++;

    }

    

     

    this->lblseconds->Text = u32Seconds.ToString();

    }

    };

     

    Thanks

    please let me know if I am misssing some thing.

    Thursday, January 12, 2012 10:13 AM

Answers

  • >To my surprise I am getting the update for every 15 secs.. which means i am not getting tick event for every 1 msec.

    That's to be expected. A Windows timer can't do better than that
    resolution.

    If you need a finer resolution have a look at some alternative means -
    such as a multimedia timer. Having said that, Windows isn't a
    deterministic real-time OS, so you're unlikely to be able to get 1ms
    precision at the best of times. If possible, re-design your solution
    so that you can accommodate variations in the period.

    Dave

    Thursday, January 12, 2012 10:22 AM

All replies

  • >To my surprise I am getting the update for every 15 secs.. which means i am not getting tick event for every 1 msec.

    That's to be expected. A Windows timer can't do better than that
    resolution.

    If you need a finer resolution have a look at some alternative means -
    such as a multimedia timer. Having said that, Windows isn't a
    deterministic real-time OS, so you're unlikely to be able to get 1ms
    precision at the best of times. If possible, re-design your solution
    so that you can accommodate variations in the period.

    Dave

    Thursday, January 12, 2012 10:22 AM
  • >To my surprise I am getting the update for every 15 secs.

    I assumed you meant 15 ms there.

    Dave

    Thursday, January 12, 2012 10:23 AM
  • Hi dave


    Thanks for quick reply


     I am getting the event at every 15 seconds..I am expecting to get every second instead..

    How do I add multimedia timer into this app??
    I am actually trying to add a user interface to simulate certain functionality..all my back end code is in c.

    Thursday, January 12, 2012 10:40 AM
  • > I am getting the event at every 15 seconds..I am expecting to get every second instead..

    You originally said "which means i am not getting tick event for every
    1 msec"

    Which is it - ms or s?

    The former is unlikely to be reliably achievable, the latter is most
    likely.

    Dave

    Thursday, January 12, 2012 12:10 PM
  • Hi Dave

    Actually I am expecting tick event for every millisecond.But this is not happening I am getting at 15 milliseconds..

    Is there any way to decrease this delay.. ??

     

    Thanks

    Thursday, January 12, 2012 12:49 PM
  • Actually I am expecting tick event for every millisecond.But this is not happening I am getting at 15 milliseconds..
    Is there any way to decrease this delay.. ??

    Not without using an alternative timer mechanism - as I mentioned
    originally.

    Dave

    Thursday, January 12, 2012 1:01 PM