Here I want to execute batch files for certain time
located in a folder.
I want to execute in such fashion:
1) First batch (it executes for certain time, get terminated)
2) second batch (after termination of first batch,second batch file should start executing..)
3)third batch(after termination of second batch third file should start executing..) and so on.
Problem is that, before termination of second batch file,third file get started and so on.
I have attached my code.plz help
TimerElapsed event also fires more than once for each event.How to make it fire only once for each event?
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Timers;
- using System.Diagnostics;
- using System.IO;
- namespace Testing_2
- {
- class Program
- {
- bool blnTimeElapsed = false;
- void TimerElapsed(object sender, ElapsedEventArgs e)
- {
- this.blnTimeElapsed = true;
- Console.WriteLine("event fire");
- }
- static void Main(string[] args)
- {
- Program run = new Program();
- run.Run();
- }
- void Run()
- {
- string[] files = Directory.GetFiles(@"C:\Files\");
- foreach (string file in files)
- {
- string filename = file;
- Process proc = new Process();
- proc.StartInfo.FileName = filename;
- Timer time = new Timer();
- time.Interval = 10000;
- time.Elapsed += new ElapsedEventHandler (TimerElapsed);
- ProcessStartInfo(filename);
- proc.Start();
- time.Enabled = true;
- Console.WriteLine(blnTimeElapsed);
- while (!proc.HasExited)
- {
- if (blnTimeElapsed)
- {
- Console.WriteLine("force fully closed");
- proc.CloseMainWindow();
- break;
- }
- }
- }
- }
- }
- }