Solved

Timer To Refresh Form - C#

Posted on 2006-11-21
8
6,220 Views
Last Modified: 2007-12-19
Hey guys,

I am after code for a timer, I need it to be running in the background and every 20 seconds refresh a form so that a textBox can be updated.

It will be updated by a function that will contain all the details of what has to go in it.  So just looking for something like this:

if timer = 20 seconds
refresh Form1
0
Comment
Question by:angus_young_acdc
  • 4
  • 3
8 Comments
 
LVL 8

Expert Comment

by:sabeesh
ID: 17985910
you can place global timer and set timer period 20 and call the function from timer_tick events.
0
 
LVL 9

Expert Comment

by:WinterMuteUK
ID: 17985981

//declare member
Timer _RefreshFormTimer = new Timer();

//In constructor of form
{
   ...
   _RefreshFormTimer.Interval = 1000 * 20; //20 seconds.
   _RefreshFormTimer.Tick += new EventHandler(RefreshFormTimer_Tick);
   ...
}

//Then the handler:
private void RefreshFormTimer_Tick(object sender, EventArgs e)
{
    //Refresh the form.
}
0
 
LVL 15

Author Comment

by:angus_young_acdc
ID: 18020389
Cant get that to work mate,  can you tell me more about where to put everything?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Accepted Solution

by:
WinterMuteUK earned 50 total points
ID: 18020501
Whereabouts is the problem?
Do you get errors?

The below 'skeleton' class should show where things go...

Cheers

Wint

public class MyForm : Form
{
   //declare member
   Timer _RefreshFormTimer = new Timer();

   //In constructor of form
   public MyForm()
   {
      InitializeComponent();
      _RefreshFormTimer.Interval = 1000 * 20; //20 seconds.
      _RefreshFormTimer.Tick += new EventHandler(RefreshFormTimer_Tick);
   }

   //Then the handler:
   private void RefreshFormTimer_Tick(object sender, EventArgs e)
   {
        //Refresh the form.
        //Here you put the code you need to refresh the form....
   }
}
0
 
LVL 15

Author Comment

by:angus_young_acdc
ID: 18026722
Hi mate,

There is no real problem per say, there are no errors or crashes.  It's just that I can't seem to get the code to do anything.  Here is the layout I am using with it:
namespace TestingTimer
{
    public partial class frmMain : Form
    {
        Timer _RefreshFormTimer = new Timer();
        public frmMain()
        {
            _RefreshFormTimer.Interval = 1000 * 20; //20 seconds.
            _RefreshFormTimer.Tick += new EventHandler(tmrRefreshForm_Tick);
        }

   private void RefreshFormTimer_Tick(object sender, EventArgs e)
   {
        MessageBox.Show("The timer works");
   }

I wanted the messagebox just so that it would show if it had worked.  All I seem to get is a blank form loading (which isnt right as the form that is meant to load is different, so the code must be creating a new one) and then nothing else.   C# isnt my greatest strength so no doubt I am making a mess of this in a really obvious way, so all help is appreciated bud.
0
 
LVL 9

Expert Comment

by:WinterMuteUK
ID: 18035139
ahhh
sorry, put:
_RefreshFormTime.Enabled = true;

after the .Tick bit.

Sorry!!! I should've put that there!!!

Wint.
0
 
LVL 15

Author Comment

by:angus_young_acdc
ID: 18035736
No worries mate and thanks that works brilliantly!  :D
0
 
LVL 9

Expert Comment

by:WinterMuteUK
ID: 18035753
Good to know!

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question