locked
Timer doesn't work... :-( RRS feed

All replies

  •  Nick Journals wrote:

    Hi guys,

     

    I created a little test addin that just shows a label.

    I added a timer to update the label with DateTime.Now, the timer ticks every second.

     

    But...the label is never updated.

    I'm sure that the timer has started, enabled,... I wrote to a textfile to confirm, but for some reason it doesn't work in the console.

     

    I found these 2 articles and tried the suggestions but it doesn't work.

    http://forums.microsoft.com/WindowsHomeServer/ShowPost.aspx?PostID=1783022&SiteID=50

    http://forums.microsoft.com/WindowsHomeServer/ShowPost.aspx?PostID=1980936&SiteID=50

     

    Anyone have any clue on how to work with a timer to update the UI?

     

    Thanks,

    Nick



    Nick,

    The best way to get an answer would be to post some of your code.  There could be any number of things that might wrong & I doubt someone is going to try and duplicate your problem on their own.  I'm not trying to be mean or snotty, but that's just they way things are. Smile
    Wednesday, February 20, 2008 5:47 PM
  • Hi Lliam,

     

    That's true ;-)

     

    Here is the most basic stuff to reproduce.

    There is nothing more to it, I also tried with the fancylistview but nothing works to refresh.

    When I do ' label1.Text = DateTime.Now.ToString();' from within a button click, it works.

     

    private System.Windows.Forms.Timer m_RefreshTimer;

     

    public HomeServerTabExtender(int width, int height, IConsoleServices consoleServices)
    {
        m_RefreshTimer = new System.Windows.Forms.Timer();
        m_RefreshTimer.Tick += new EventHandler(m_RefreshTimer_Tick);
        m_RefreshTimer.Interval = 1000;
        m_RefreshTimer.Start();
    }


    void m_RefreshTimer_Tick(object sender, EventArgs e)
    {
        label1.Text = DateTime.Now.ToString();
    }

     

    Tnx,

    Nick

    Wednesday, February 20, 2008 6:09 PM
  •  Nick Journals wrote:

    Hi Lliam,

     

    That's true ;-)

     

    Here is the most basic stuff to reproduce.

    There is nothing more to it, I also tried with the fancylistview but nothing works to refresh.

    When I do ' label1.Text = DateTime.Now.ToString();' from within a button click, it works.

     

    private System.Windows.Forms.Timer m_RefreshTimer;

     

    public HomeServerTabExtender(int width, int height, IConsoleServices consoleServices)
    {
        m_RefreshTimer = new System.Windows.Forms.Timer();
        m_RefreshTimer.Tick += new EventHandler(m_RefreshTimer_Tick);
        m_RefreshTimer.Interval = 1000;
        m_RefreshTimer.Start();
    }


    void m_RefreshTimer_Tick(object sender, EventArgs e)
    {
        label1.Text = DateTime.Now.ToString();
    }

     

    Tnx,

    Nick



    Are you positive that m_RefreshTimer_Tick is getting called from within the console?  System.Windows.Forms.Timer() is a single threaded timer and may not work properly from within the console.  You can try System.Timers.Timer or System.ThreadingTimer instead.

    Also, setting the .Text property on the label should tell the parent form to update, but just in case you may want to put an Invalidate or Update or send a PAINT message to the parent form.


    Wednesday, February 20, 2008 6:45 PM
  • I already tried with System.Timers also.

    Used the Invalidate also, I'll have a try with paint.

     

    The timer itself seems to work, when I write to a file on every tick it gets logged. It's just the UI that won't cooperate. :-(

     

    Nick

    Thursday, February 21, 2008 7:12 AM
  •  Nick Journals wrote:

    I already tried with System.Timers also.

    Used the Invalidate also, I'll have a try with paint.

     

    The timer itself seems to work, when I write to a file on every tick it gets logged. It's just the UI that won't cooperate. :-(

     

    Nick



    I did get a chance to test it and it works for me.  Here's the code I used:


                mTimer = new System.Timers.Timer();
                mTimer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
                mTimer.Interval = 1000;
                mTimer.AutoReset = true;
                mTimer.Start();
            }

            void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                this.mValueLabel.Text = DateTime.Now.ToLongTimeString();
            }

    No refresh of the UI required.  It did not work with the Windows.Forms.Timer class though.

    Thursday, February 21, 2008 9:31 AM
  •  

    I will have a try tonight.

    And if it doesn't work I'll post the whole test addin.

     

    Thanks for the help!

    Thursday, February 21, 2008 11:52 AM