8 Replies - 3322 Views - Last Post: 15 August 2010 - 07:10 AM Rate Topic: -----

#1 cuda66  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-August 10

multiple instances of the same exe

Posted 14 August 2010 - 10:04 PM

Hy!
I'm using some code to start an exe file instance (that will run as process) in the click event of a button.
This is the code:
Process p = null;
                
                
                    string targetDir;
                    targetDir = string.Format(@"C:\test");
                    
                    p = new Process();
                    p.StartInfo.WorkingDirectory = targetDir;
                    p.StartInfo.FileName = "test.exe";
                    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    p.StartInfo.Arguments=" ";

                    
                    p.Start();
                    
                    this.Cursor = Cursors.WaitCursor;
                
                    p.WaitForExit();
                    p.Close();


My question is this: How can I modify the code to start multiple instances of this exe process - the number of instances being taken from an textbox1.text at an certain time interval taken from an textbox2.text???

This post has been edited by cuda66: 14 August 2010 - 10:07 PM


Is This A Good Question/Topic? 0
  • +

Replies To: multiple instances of the same exe

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,355
  • Joined: 02-June 10

Re: multiple instances of the same exe

Posted 14 August 2010 - 10:10 PM

Lots of programs do there own instance limitations. All the stuff my company produces for example is 1 instance only. You're not going to override the code within someone else's executable.
Was This Post Helpful? 0
  • +
  • -

#3 cuda66  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-August 10

Re: multiple instances of the same exe

Posted 14 August 2010 - 10:27 PM

It's only a batch converted to exe...
Very small memory footprint, and proc usage...
I don't see the problem in wanting to run multiple instances of this exe which I created...
Was This Post Helpful? 0
  • +
  • -

#4 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 995
  • View blog
  • Posts: 2,385
  • Joined: 04-October 09

Re: multiple instances of the same exe

Posted 14 August 2010 - 11:10 PM

Create a timer, set it to the interval you want and in the event start your process. Subtract one from the count in the text box and when it reaches zero, stop the timer.
Was This Post Helpful? 0
  • +
  • -

#5 cuda66  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-August 10

Re: multiple instances of the same exe

Posted 14 August 2010 - 11:17 PM

I don't think that it is that simple...
I already tried that and this resolves the interval to start process BUT the multiple instances of the same process does not work...
For some reason the application hangs...
Maybe I don't know how to set the timer in accord with starting multiple instances...I don't know...
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,352
  • Joined: 29-May 08

Re: multiple instances of the same exe

Posted 14 August 2010 - 11:52 PM

View Postcuda66, on 15 August 2010 - 06:17 AM, said:

For some reason the application hangs...


Have a look through the source code you provided, which line do you think is the likely cause?
Was This Post Helpful? 0
  • +
  • -

#7 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: multiple instances of the same exe

Posted 15 August 2010 - 03:51 AM

Try using asynchronous events, or threads. Make a thread, use ParameterizedThreadStart, give it a time to sleep until, and then fire up x number of threads. Then, in the thread, simply Join that thread for that time you gave it and once it resumes, make it run the process code.

Job done :)

http://msdn.microsof...ing.thread.aspx
http://msdn.microsof...hreadstart.aspx
http://msdn.microsof...hread.join.aspx
Was This Post Helpful? 1
  • +
  • -

#8 cuda66  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 04-August 10

Re: multiple instances of the same exe

Posted 15 August 2010 - 03:58 AM

View PostImdsm, on 15 August 2010 - 02:51 AM, said:

Try using asynchronous events, or threads. Make a thread, use ParameterizedThreadStart, give it a time to sleep until, and then fire up x number of threads. Then, in the thread, simply Join that thread for that time you gave it and once it resumes, make it run the process code.

Job done :)

http://msdn.microsof...ing.thread.aspx
http://msdn.microsof...hreadstart.aspx
http://msdn.microsof...hread.join.aspx


Thanks a lot!
I finally solved the problem.
Was This Post Helpful? 0
  • +
  • -

#9 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: multiple instances of the same exe

Posted 15 August 2010 - 07:10 AM

View Postcuda66, on 15 August 2010 - 02:58 AM, said:

View PostImdsm, on 15 August 2010 - 02:51 AM, said:

Try using asynchronous events, or threads. Make a thread, use ParameterizedThreadStart, give it a time to sleep until, and then fire up x number of threads. Then, in the thread, simply Join that thread for that time you gave it and once it resumes, make it run the process code.

Job done :)

http://msdn.microsof...ing.thread.aspx
http://msdn.microsof...hreadstart.aspx
http://msdn.microsof...hread.join.aspx


Thanks a lot!
I finally solved the problem.


You're welcome :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1