| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Jan 19, 2008 10:08 am Post subject: [Help] C# Timers |
|
|
| Code: |
Timer t1 = new Timer();
t1.Enabled = true;
t1.Interval = 1000; //if i'm not making a mistake it suppose to be 10 seconds
t1.Start();
|
so i'v created a timer and now i wanna print it on console screen and watch him decreased any second. how do i do that?!? i tried to do
| Code: |
Console.WriteLine(t1);
|
but all i get from that is System.Timers ... bla bla... interval = 1000;
:S :S _________________
Stylo |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jan 19, 2008 10:46 am Post subject: |
|
|
In your initalization of the timer, do this:
| Code: |
timer1.Tick += new new EventHandler (t_tick);
|
then (if you don't let VS do this for you), create a new method:
| Code: |
private static void t_tick(object sender, TimerEventArgs e)
{
//do whatever you want it to do when each interval comes up
}
|
_________________
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Sat Jan 19, 2008 11:07 am Post subject: |
|
|
| Code: | private void t1_Tick(object sender, EventArgs e)
{
//specify what you would like to do at each tick!
} |
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jan 19, 2008 11:09 am Post subject: |
|
|
| Naablet wrote: | | Code: | private void t1_Tick(object sender, EventArgs e)
{
//specify what you would like to do at each tick!
} |
|
That won't work if the user hasn't given the timer another event handler. _________________
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Sat Jan 19, 2008 11:13 am Post subject: |
|
|
| samuri25404 wrote: | | Naablet wrote: | | Code: | private void t1_Tick(object sender, EventArgs e)
{
//specify what you would like to do at each tick!
} |
|
That won't work if the user hasn't given the timer another event handler. |
Oh i see.
so with this code you can add a handler while running the program?
| Code: | | timer1.Tick += new new EventHandler (t_tick); |
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Jan 19, 2008 1:47 pm Post subject: |
|
|
i'm getting error with the word TimerEventArgs.
it says that there's no such thing :s
btw another question.. how do i convert millisecond into a second? _________________
Stylo
Last edited by Stylo on Sat Jan 19, 2008 2:21 pm; edited 1 time in total |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jan 19, 2008 2:18 pm Post subject: |
|
|
Ok, then just do "EventArgs" _________________
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Jan 19, 2008 2:22 pm Post subject: |
|
|
thx the timer is working but how do i convert millisecond into a seconds? _________________
Stylo |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sat Jan 19, 2008 2:56 pm Post subject: |
|
|
If you mean by watching it decrease in the console then whenever you print it to console print it / 1000 _________________
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Sat Jan 19, 2008 3:04 pm Post subject: |
|
|
Why don't u just manually add the event!
-.-
Like i do.
Propeties --> events _________________
Intel over amd yes. |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Jan 19, 2008 3:30 pm Post subject: |
|
|
Because it's a Console Application. _________________
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Sat Jan 19, 2008 3:42 pm Post subject: |
|
|
| samuri25404 wrote: | | Because it's a Console Application. |
Oh.
That's explains it. _________________
Intel over amd yes. |
|
| Back to top |
|
 |
|