.NET Framework Bookmark and Share   
 index > Building Development and Diagnostic Tools for .Net > Managing Multiple Instance of the same process
 

Managing Multiple Instance of the same process

I want to start multiple instance of a process,lets say notepad and associate with some name like note1,note2 and store the same in DB.From the web UI on can start n number of the process and associate with a name.Now the problem is i can start say 5 process of notepad and associate with a name.when i stop notepad1 and notepad5 and try to start notepad1 and notepad5 i couldn't differentiate the process id as there are already 3 process runnig with the same name.So please if any one can help me with some code to manage multiple instance of same process would be more helpful.

Note: Am trying to start an third part application from command prompt and need to get the return output from command prompt.

Code:

string cmd;
cmd = "thirdpartyapp.exe" ;

ProcessStartInfo si = new ProcessStartInfo("cmd.exe");
// Redirect both streams so we can write/read them.
si.RedirectStandardInput = true;
si.RedirectStandardOutput = true;
si.UseShellExecute = false;
// Start the procses.
Process p = Process.Start(si);
// Issue the dir command.
p.StandardInput.WriteLine(@"cd\");
p.StandardInput.WriteLine(@"cd C:\Program Files\thirdpartyapp\");
p.StandardInput.WriteLine(cmd);
Thread.Sleep(5000);
Process[] localByName = Process.GetProcessesByName("thirdpartyapp");
p.Kill();

am killing the process p in order to read the command output and continue with execution.
ASP.Net _ Oracle
I have done it.What i did is i took all the process in an array using the process name.Then i compared each of the process starttime with one another and took the process id of the process having the greatest starttime.

All Replies

  • Saturday, August 08, 2009 4:51 PMJon LangdonMSFT, OwnerUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I'm having a hard time understanding your overall scenario, but perhaps you can use the Id property of the Process object to distinguish processes with the same name. These Ids can be re-used by the system, but it may be unique enough for your purposes. It's guaranteed to be unique across the set of currently running processes, however.

    Regards,
    Jon
ASP.Net _ Oracle
Actually am running multiple instance of an application (notepad),i want to get the process id of the application which is started recently.
ASP.Net _ Oracle
The returned Process instance has an Id property - is that what you're looking for ?

Paul
p.b.a
Yes.I need to have the Id of the recently started process out of the multiple instance of the same process running earlier.
ASP.Net _ Oracle

You can use google to search for other answers

Custom Search

More Threads

• Profiler get string argument value - GetStringLayout?
• How increases the CodeCompileUnit in method to the code file in
• Adding a VB/C# Editor into a .NET application
• Signing an assembly in C#
• Help to get started on a process blocker tool for work
• Reading metadata for debugger
• JMC support in MDbg?
• .NET profiler
• Suspend profiling?
• Debugging Custom Attributes