473,588 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to execute batch files at a specific time in folder

1 New Member
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 3027
GaryTexmo
1,501 Recognized Expert Top Contributor
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
2781
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 correct order to create the database. What is the syntax for executing script files from Transact-SQL?
7
9063
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 could run simultaneously, but that might break Windows... ;) The problem I had was I couldn't get the files to RUN, only to OPEN. Thanks for the help!!! pseudo-code looks like this
6
11209
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 programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe...
1
3166
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 programs and executing registry entries. The majority of my buttons work however, I have come upon a problem. I need a few of the buttons to run DOS batch files, the batch files in turn run program installers (specifically windows update runtime .exe...
3
11541
by: Danel | last post by:
In VB60 we had Shell. How can one execute a .BAT file in DOTNET. Thanks
1
5384
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 statement of my batch file. Since I assume that this slows down the whole process I would like to know if there is a way to suppress that echo and only get error messages and
4
6422
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 thinking the following might help. I would appreciate if someone could comment on this idea and possibly suggest a better one: The environement variable in question is 'Path' in the HKCU registry folder's Environment key. I want to add some...
2
1398
by: dvk | last post by:
Hai, Can anybody pls tell me how to execute a batch file (which is in network shared folder)?
0
7367
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 occurred while executing batch. Error message is: The directory name is invalid. After initial investigation, found that this error is thrown when we execute an existing sql query file with the Results To Grid option is set and does not occur if the...
17
10291
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 one macro that will call other macros. So I am thinking I need to figure out how to run DOS Batch files from Access and incorporate them in my Access dB. I think I have to use Shell / VBA. If, for example, my batch file was Transfer01in.bat, the...
0
7929
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8354
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8223
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3883
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2371
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.