473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to execute batch files at a specific time in folder

Hi all,

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
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Timers;
  5. using System.Diagnostics;
  6. using System.IO;
  7.  
  8. namespace Testing_2
  9. {
  10.     class Program
  11.     {
  12.         bool blnTimeElapsed = false;
  13.  
  14.         void TimerElapsed(object sender, ElapsedEventArgs e)
  15.         {
  16.             this.blnTimeElapsed = true;
  17.             Console.WriteLine("event fire");
  18.         }
  19.  
  20.         static void Main(string[] args)
  21.         {
  22.             Program run = new Program();
  23.             run.Run();
  24.         }
  25.         void Run()
  26.         {
  27.             string[] files = Directory.GetFiles(@"C:\Files\");
  28.             foreach (string file in files)
  29.             {
  30.                 string filename = file;
  31.                 Process proc = new Process();
  32.                 proc.StartInfo.FileName = filename;
  33.                 Timer time = new Timer();
  34.                 time.Interval = 10000;
  35.                 time.Elapsed += new ElapsedEventHandler  (TimerElapsed);
  36.                  ProcessStartInfo(filename);
  37.                 proc.Start();
  38.                 time.Enabled = true;
  39.                 Console.WriteLine(blnTimeElapsed);
  40.                 while (!proc.HasExited)
  41.                 {
  42.                     if (blnTimeElapsed)
  43.                     {
  44.  
  45.                        Console.WriteLine("force fully closed");
  46.                         proc.CloseMainWindow();
  47.                         break;
  48.                      }
  49.                 }
  50.             }
  51.          }
  52.     }
  53. }
  54.  
  55.  
Sep 23 '10 #1
1 3012
GaryTexmo
1,501 Expert 1GB
Is the purpose of this timer to serve as a timeout? Like, if your process takes too long to execute, it will fire the event and abort processing?

Your event looks fine... 10 seconds? I don't know why it fires twice in quick succession. You could disable your event in the firing code and that would make sure it gets fired only the one time.

I'm not seeing a second event firing when I try a similar thing...

Expand|Select|Wrap|Line Numbers
  1.         private static int m_runCount = 0;
  2.  
  3.         static void Main(string[] args)
  4.         {
  5.             Timer t = new Timer();
  6.             t.Interval = 1000;
  7.             t.Elapsed += new ElapsedEventHandler(t_Elapsed);
  8.             t.Start();
  9.  
  10.             while (m_runCount < 10)
  11.             {
  12.             }
  13.  
  14.             Console.WriteLine();
  15.             Console.WriteLine("Execution finished");
  16.         }
  17.  
  18.         static void t_Elapsed(object sender, ElapsedEventArgs e)
  19.         {
  20.             Console.WriteLine("Event fired... executed iteration " + m_runCount.ToString());
  21.  
  22.             m_runCount++;
  23.         }
Maybe the extra fire is related to why it's starting the second batch too early?
Sep 23 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Phil | last post by:
Hi, I have my create statments for tables, procedures, views, etc in individual Transact-SQL script files (.sql). I wnat to write another script file that executes these scripts in the...
7
by: erniedude | last post by:
Hi, I'm a newbie and I was wondering if anyone knew a (Python) script to run 4 batch files, one after the other (assuming the directories are known). It would be better if all 4 batch files...
6
by: Charles Neitzel | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running...
1
by: Charles | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running...
3
by: Danel | last post by:
In VB60 we had Shell. How can one execute a .BAT file in DOTNET. Thanks
1
by: matthias | last post by:
I have to execute fairly large batch files (200-300MB) with several million INSERT commands. When I do that from pgsql using the \i switch, I get the echo INSERT 0 1 for every single insert...
4
by: Shiraz | last post by:
Hi I'm using Visual Studio Installer to make my installer, and have not as yet figured out a straightforward way to use it to set environmental variables. Amongst the various things I tried, I'm...
2
by: dvk | last post by:
Hai, Can anybody pls tell me how to execute a batch file (which is in network shared folder)?
0
by: hi4murali | last post by:
Facing a strange error in MS SQL Management Studio 2005, when trying to open a new query window, open a table to view data or even run and existing SQL query file. The error text is: An error...
17
by: Merch | last post by:
I need to transfer entire excel files (not just a range of data) from one directory to another using an Access Macro because I want to intersperse them with my other macros in Access. I want to run...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.