Example #1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                _timer1 = new Timer {
                    Interval = 5000
                };                                          // every 5 seconds

                _timer1.Elapsed          += Timer1_Tick;
                _timer1.Enabled           = true;
                Thread.CurrentThread.Name = "Main Thread";
                Library.WriteLog("Test Windows Service Started");
            }
            catch (Exception e)
            {
                Library.WriteLog("Error on starting windows service, excpetion details will follow - ");
                Library.WriteErrorLog(e);
            }
        }
        public FileInputMonitor()
        {
            DirectoryInfo dir = new DirectoryInfo(folderToWatchFor);

            if (dir.Exists)
            {
                fileSystemWatcher = new FileSystemWatcher(folderToWatchFor);

                // Instruct the file system watcher to call the FileCreated method
                // when there are files created at the folder.
                fileSystemWatcher.Created += new FileSystemEventHandler(FileCreated);

                fileSystemWatcher.EnableRaisingEvents = true;
            }
            else
            {
                Library.WriteErrorLog("watch folder directory doesn't exists");
                Library.LogEvent("watch folder directory doesn't exists at " + DateTime.Now.ToString());
            }
        } // end FileInputMonitor()
Example #3
0
 protected override void OnStop()
 {
     this.timer1.Enabled = false;
     Library.WriteErrorLog("Test window service stopped");
 }
Example #4
0
        private void Timer1_Elapsed(object sender, ElapsedEventArgs e)
        {
            //Write code here to do some job depends on your requirement

            Library.WriteErrorLog("Timer ticked and some job has been done successfully");
        }
Example #5
0
 private void timer1_tick(object sender, ElapsedEventArgs e)
 {
     // write code here to get executed every time the timer triggers.
     Library.WriteErrorLog("Timer ticked and some jobs has been done successfully");
 }
Example #6
0
 protected override void OnStop()
 {
     // Writes the text "Test windows service stopped" to the logFile.
     Library.WriteErrorLog("Test windows service stopped");
 }
Example #7
0
 private void timer1_Tick(object sender, ElapsedEventArgs e)
 {
     Library.WriteErrorLog("Timer ticked and some job has been done successfully");
 }
 protected override void OnStop()
 {
     fileInputMonitor.OnStopFileMonitoring();
     Library.WriteErrorLog("Service is stopping for file watching");
     Library.LogEvent("Service is stopping for file watching at " + DateTime.Now.ToString());
 }
        //for running as console app then need to exclude Program.cs and change project properties
        //private static void Main(string[] args)
        //{
        //    var service = new FileInputMonitorService();
        //    if (Environment.UserInteractive)
        //    {
        //        service.OnStart(args);
        //        Console.WriteLine("Press any key to stop the program");
        //        Console.Read();
        //        service.OnStop();
        //    }
        //    else
        //    {
        //        Run(service);
        //    }
        //}

        protected override void OnStart(string[] args)
        {
            Library.WriteErrorLog("Service is started for file watching");
            Library.LogEvent("Service is started for file watching at " + DateTime.Now.ToString());
            fileInputMonitor = new FileInputMonitor();
        }
Example #10
0
 private void timer1_Tick(object sender, ElapsedEventArgs e)
 {
     Library.WriteErrorLog("Timer Ticked and some job has been already ticked");
 }
Example #11
0
 protected override void OnStop()
 {
     timer1.Enabled = false;
     Library.WriteErrorLog("Test Window Service Stopped");
 }