473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to run the method in a schedule??

HI~

I am coding a program that need to run a method in a schedule when
start a program, but i have no idea to make it(how to code it). Can
someone help me please?

My case:

The user can input many task(start time, stop time and action(call
which method)) at the same time, just like a table. When the current
time is equal the start time in each row of table, it will run a
method(for example: call a method to printout something in the
textbox...etc).

Is there any simple code for me to reference?

THX~
Nov 22 '05 #1
4 2142

You need to use one of the Timer classes. Look at System.Timers.Timer, it
lets you execute something after a given interval.

-Oleg.

"yindevil" <yi******@groupx.net> wrote in message
news:c4**************************@posting.google.c om...
HI~

I am coding a program that need to run a method in a schedule when
start a program, but i have no idea to make it(how to code it). Can
someone help me please?

My case:

The user can input many task(start time, stop time and action(call
which method)) at the same time, just like a table. When the current
time is equal the start time in each row of table, it will run a
method(for example: call a method to printout something in the
textbox...etc).

Is there any simple code for me to reference?

THX~

Nov 22 '05 #2

You need to use one of the Timer classes. Look at System.Timers.Timer, it
lets you execute something after a given interval.

-Oleg.

"yindevil" <yi******@groupx.net> wrote in message
news:c4**************************@posting.google.c om...
HI~

I am coding a program that need to run a method in a schedule when
start a program, but i have no idea to make it(how to code it). Can
someone help me please?

My case:

The user can input many task(start time, stop time and action(call
which method)) at the same time, just like a table. When the current
time is equal the start time in each row of table, it will run a
method(for example: call a method to printout something in the
textbox...etc).

Is there any simple code for me to reference?

THX~

Nov 22 '05 #3
I found these code from MSDN

using System;
using System.Threading;

class TimerExampleState
{
public int counter = 0;
public Timer tmr;
}

class App
{
public static void Main()
{
TimerExampleState s = new TimerExampleState();

// Create the delegate that invokes methods for the timer.
TimerCallback timerDelegate = new TimerCallback(CheckStatus);

// Create a timer that waits one second, then invokes every second.
Timer timer = new Timer(timerDelegate, s,1000, 1000);

// Keep a handle to the timer, so it can be disposed.
s.tmr = timer;

// The main thread does nothing until the timer is disposed.
while(s.tmr != null)
Thread.Sleep(0);
Console.WriteLine("Timer example done.");
}
// The following method is called by the timer's delegate.

static void CheckStatus(Object state)
{
TimerExampleState s =(TimerExampleState)state;
s.counter++;
Console.WriteLine("{0} Checking Status
{1}.",DateTime.Now.TimeOfDay, s.counter);
if(s.counter == 5)
{
// Shorten the period. Wait 10 seconds to restart the timer.
(s.tmr).Change(10000,100);
Console.WriteLine("changed...");
}
if(s.counter == 10)
{
Console.WriteLine("disposing of timer...");
s.tmr.Dispose();
s.tmr = null;
}
}
}

I think these code can solve my problem, but it can handle one task
only... how can i edit it to handle multi task? I don't know how to
edit it...
"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message news:<10*************@corp.supernews.com>...
You need to use one of the Timer classes. Look at System.Timers.Timer, it
lets you execute something after a given interval.

-Oleg.

"yindevil" <yi******@groupx.net> wrote in message
news:c4**************************@posting.google.c om...
HI~

I am coding a program that need to run a method in a schedule when
start a program, but i have no idea to make it(how to code it). Can
someone help me please?

My case:

The user can input many task(start time, stop time and action(call
which method)) at the same time, just like a table. When the current
time is equal the start time in each row of table, it will run a
method(for example: call a method to printout something in the
textbox...etc).

Is there any simple code for me to reference?

THX~

Nov 22 '05 #4
I found these code from MSDN

using System;
using System.Threading;

class TimerExampleState
{
public int counter = 0;
public Timer tmr;
}

class App
{
public static void Main()
{
TimerExampleState s = new TimerExampleState();

// Create the delegate that invokes methods for the timer.
TimerCallback timerDelegate = new TimerCallback(CheckStatus);

// Create a timer that waits one second, then invokes every second.
Timer timer = new Timer(timerDelegate, s,1000, 1000);

// Keep a handle to the timer, so it can be disposed.
s.tmr = timer;

// The main thread does nothing until the timer is disposed.
while(s.tmr != null)
Thread.Sleep(0);
Console.WriteLine("Timer example done.");
}
// The following method is called by the timer's delegate.

static void CheckStatus(Object state)
{
TimerExampleState s =(TimerExampleState)state;
s.counter++;
Console.WriteLine("{0} Checking Status
{1}.",DateTime.Now.TimeOfDay, s.counter);
if(s.counter == 5)
{
// Shorten the period. Wait 10 seconds to restart the timer.
(s.tmr).Change(10000,100);
Console.WriteLine("changed...");
}
if(s.counter == 10)
{
Console.WriteLine("disposing of timer...");
s.tmr.Dispose();
s.tmr = null;
}
}
}

I think these code can solve my problem, but it can handle one task
only... how can i edit it to handle multi task? I don't know how to
edit it...
"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message news:<10*************@corp.supernews.com>...
You need to use one of the Timer classes. Look at System.Timers.Timer, it
lets you execute something after a given interval.

-Oleg.

"yindevil" <yi******@groupx.net> wrote in message
news:c4**************************@posting.google.c om...
HI~

I am coding a program that need to run a method in a schedule when
start a program, but i have no idea to make it(how to code it). Can
someone help me please?

My case:

The user can input many task(start time, stop time and action(call
which method)) at the same time, just like a table. When the current
time is equal the start time in each row of table, it will run a
method(for example: call a method to printout something in the
textbox...etc).

Is there any simple code for me to reference?

THX~

Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: yindevil | last post by:
HI~ I am coding a program that need to run a method in a schedule when start a program, but i have no idea to make it(how to code it). Can someone help me please? My case: The user can...
7
by: stephane | last post by:
Hi, I must implement the method printLn of the class Thoraire. And I've done this, can someone tell me if I am right ?
1
by: stephane | last post by:
Hi again, I would like to make sure I am right (if I am). This is the last time I'll bother you with this code I promise! It's just that I don't have a teacher and I have to prepare an exam. I...
1
by: aleksander.hansen | last post by:
Hello, I have xml data that I need to group and sort. I have tried grouping it using the Muenchian Method. Probably not solved the best way, but it works. But I can't get the sorting right. ...
3
by: BLUE | last post by:
I've to call 2 web method from time to time so that the web service will do cleanup and sync jobs on a database. These methods can be called once every X days where X >= Y for the sync method...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.