Click here to Skip to main content
15,942,449 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I created a Window Service project. When it is started, it will create/update an Oracle Table and the Oracle table can be viewed. However, the scheduled task does not work. The related code is below. In the FirstTask(), the trainArray retrieves on-line data from a website, and then update the Oracle table. Appreciate if you can hint me how to debug it.

C#
protected override void OnStart(string[] args)  {
    System.Timers.Timer timScheduledTask = new System.Timers.Timer();
    timScheduledTask.Interval = 2 * 1000;
    timScheduledTask.Enabled = true;
    timScheduledTask.Elapsed += new System.Timers.ElapsedEventHandler(timScheduledTask_Elapsed);
}
void timScheduledTask_Elapsed(object sender, System.Timers.ElapsedEventArgs e)    {
    FirstTask(tblTrain, tblDestination, tblTrackCircuit_Geocode);
}

void FirstTask(DataTable tbl_Train, DataTable tbl_Dest, DataTable tbl_TrkGeo)  {
    string[,] trainArray = g.GetDataArrayFromWeb();
    long eTime = g.UnixTimestampFromDateTime(DateTime.Now);

    // Insert the array's data into Oracle table
    UpdateOracleTable(eTime, trainArray, tblTrackCircuit_Geocode, sTblName);
}
Posted

1 solution

Your timScheduledTask is local to the method -- it should probably be a field.
 
Share this answer
 
Comments
s yu 16-Jul-14 10:45am    
My program worked a couple of days using the same code in OnStart(), including the timeScheduledTask variable. It should not be matter if it is a field.
PIEBALDconsult 16-Jul-14 10:49am    
Well then humor me and try it anyway.
s yu 16-Jul-14 12:37pm    
I created a method to track the Window Service's in OnStart() (as well as in OnStop()):
Write2Log(" WindowsService: Service Started at ");
which records the service start time in a .txt. The problem is something wrong in my dabatse updating, rather than the scheduled task. I should close this instance. Thanks to all reviewers.
PIEBALDconsult 16-Jul-14 12:49pm    
I don't think you understand Windows Services.
s yu 16-Jul-14 14:08pm    
I am new using Window Service application. Wish you can provide some help. Right now, I got Error 1053. Still debugging on it.

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