Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi!

I'm trying to make a dice game in c# (a windows form application). Been trying to find out how to use the timer function but can't work it out.
What it is supposed to do is to start a game where the computer is playing against itself if no choice has been done after 15sec. If anyone could help me with this i would be extremely happy!
Posted
Updated 12-Dec-10 2:40am
v2
Comments
Abdul Quader Mamun 12-Dec-10 8:40am    
Spelling Check.
girlie23 15-Dec-10 16:39pm    
Thank you so much! got it working now!!! only problem is that i can't work out how to turn it off if u click a button in the application. Don't know if it is cause i'm tired or what it is but if someone could help that would be very nice! And again thank u for your answeres used a bit of a mix actually... will post it here when it's done.

Here[^] is a simple example using a timer.

As you will see from the comments in the code, a value of 1000 represents 1 second so in your case you would use 15000 (15 secs).

You then put the code you want to execute at that interval in the Tick() event handler.
 
Share this answer
 
Thank you for your question. You can follow the bellow code.

C#
public void SetTimer()
{
    System.Timers.Timer aTimer = new System.Timers.Timer();
    aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
    aTimer.Interval=10000;
    aTimer.Enabled=true;
}
// Specify what you want to happen when the Elapsed event is raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
            //your code
}



Thanks,
Mamun
 
Share this answer
 
v3
C#
private void WaitForChoice()
{
    Timer1.Interval = 15000;  // milliseconds
    Timer1.Enabled = true;
}

private void Timer1_Tick(object sender, EventArgs e)
{
    Timer1.Enabled = false;
    StartGameDemo();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900