how to write a this program

  • Thread starter Thread starter C#User
  • Start date Start date
C

C#User

i want this program every some specific time (15 mins) to do something. I
don't know how to do it. Shall i use threads or other technologies?

Thanks.
 
Use a System.Timer, and set it to 60000. It'll fire every 1 minute. Then
have a member variable keeping track of how many times the event's been
fired. When it hits fifteen do whatever.
 
C#User said:
i want this program every some specific time (15 mins) to do something. I
don't know how to do it. Shall i use threads or other technologies?

Just use a System.Timers.Timer timer object ans supply a method to be called
every 15 minutes. This timer, unlike the System.Windows.Form.Timer timer,
will execute your callback method in another thread wich, even if the method
takes a long time to execute, will not delay the following execution.
 
C#User said:
i want this program every some specific time (15 mins) to do something. I
don't know how to do it. Shall i use threads or other technologies?

Thanks.

Either write a command line utility and schedule it with task scheduler to
run periodically, or write a service and start a thread which sleeps and
loops, or use COM+ on XP/Server 2003.

David
 
TomB said:
Use a System.Timer, and set it to 60000. It'll fire every 1 minute. Then
have a member variable keeping track of how many times the event's been
fired. When it hits fifteen do whatever.

What prevents one from setting its Interval property (which is a double) to
900000 (15 minutes)? That's actually one of the key difference between a
System.Timers.Timer and a winform timer. I don't really see the point of
setting it to one minute and counting manually the number of minutes
elapsed....
 
I actually wrote my own scheduling program to do things of the sort.
the basic implementation is to have a scheduler class that has a method:
AddTask(Task task, DateTime time);
and a while(true) loop with an inner loop that checks for tasks to run.
I then made what a task can do very cool, it runs programs, executes sql,
does bulk copys, downloads files.
it's hot.
 
Eric,
That's right. I should call it scheduling program. Actually i have a table
in DB like below:

customer time
cus1 8:15am
cus2 10:15am

when the time is met(say,right now is 8:15), it will actually copy some
files to some directory.

Would you mind tell me how to accomplish that?

Thanks.
 
If you need to update the gui after the 15 minutes, may as well use a Form
timer so you don't have another thread or Invoke issues to deal with. If
you need to invoke anyway to update form elements, may as well do it in form
timer method and get rid of some fluff. Get it depends on what is really
going on.
 
Syncfusion claims their's is the fastest. It is easy to use, but I have
never tested it against others for performance. The virtual grid is fast
though.
 
well, here's my program in it's essence.

Classes:
-----------------------------
ICommand // implement this one with classes that download files, copy files,
sql, etc.
void run();
-----------------------------
Task
ArrayList commands; // of Type ICommand
void run(); //runs all commands.
-----------------------------
TaskManager
void AddTask(Task task);
Task GetTaskByKey(string key);
-----------------------------
-----------------------------
Schedule
Task Task {get;set;}
DateTime GetNextRuntime();
void RunNow(); // calls task.Run(), which runs all commands.
-----------------------------
Scheduler
void AddSchedule(Schedule schedule);
void loopthread(){ // start this from Form1
foreach(Schedule s in schedules){
if(s.Status == ScheduleStatus.Waiting){
new MethodInvoker(s.RunNow).BeginInvoke(null, null);
}
}
}
-----------------------------

Then have a form with a grid or list box that with DataSource =
Scheduler.Schedules

So that's that basic architecture of my program.

Some method names have been changed to protect the innocen :)

Good luck.
 
clarification:
void loopthread(){ // start this from Form1
while(true){
Thread.Sleep(30000); // addition: this loop runs for ever, but wakes up
every 30secs to check if any schedules need to run
foreach(Schedule s in schedules){
if(s.Status == ScheduleStatus.Waiting
&& s.GetNextRun() < DateTime.Now // also, it needs to
be past the time to run.
){
 
Back
Top