public void RunTask() { Library.Windows.StopWatch TskWat = null; try { //--- Init and start the task watch TskWat = new Library.Windows.StopWatch(); TskWat.Start(); //--- Create a new task start message and run the task ServiceTarget.ProgressManager.CreateMessage(new ProgressMessage(ID, ProgressMessage.enRunState.Start)); Run(); } catch (Exception Exc) { CreateMessage(Exc); } finally { //--- Dispose the task and stop the task watch Dispose(); TskWat.Stop(); //--- Set the last run parameters LastRunDate = DateTime.Now; LastRunDuration = TskWat.Elapsed; //--- Set the task last run parameters ServiceTarget.ConfigFile.SetDateTime(GetConfigNodePath(NodName_Tsk_LastRunDat), LastRunDate); ServiceTarget.ConfigFile.SetTimeSpan(GetConfigNodePath(NodName_Tsk_LastRunDur), LastRunDuration); //--- Update the config file and create a new task finish message ServiceTarget.ConfigFile.Update(); ServiceTarget.ProgressManager.CreateMessage(new ProgressMessage(ID, ProgressMessage.enRunState.Finish)); } }
public ProgressManager(string sLogPath) { //--- Init the file watcher FileWatcher = new FileWatcher(Path.Combine(sLogPath, FileName_Msg)); //--- Init and start the mesage watch MessageWatch = new Library.Windows.StopWatch(); MessageWatch.Start(); //--- Init the message timer and set the event handler MessageTimer = new Timer(); MessageTimer.Interval = Itv_ChkMsg; MessageTimer.Tick += OnMessageTimerTick; }
protected FileStream OpenMessageFile(FileAccess FileAcc) { FileStream FileStr = null; Library.Windows.StopWatch FileWat = null; //--- Init and start the fgile watch FileWat = new Library.Windows.StopWatch(); FileWat.Start(); //--- Open the repository file or timeout while (true) { try { //--- Open the repository file FileStr = File.Open ( FileWatcher.FileName, FileAcc == FileAccess.Read ? FileMode.Open : FileMode.OpenOrCreate, FileAcc, FileShare.None ); break; } catch (IOException Exc) { //--- Check timeout if (FileWat.ElapsedMilliseconds > Timeout_MsgFile) { throw new Exception(ErrMsg_TimeoutMsgFile.Replace("%file%", FileWatcher.FileName)); } //--- Pause for the next file access Library.Windows.Windows.Pause(Del_MsgFile); continue; } } return(FileStr); }