Process.start wait for a callback
-
Hi, I have two .net application (exe). Prog1 and Prog2 What I would like to do is run the first program (prog1) and then from "prog1" run the second prgram "prog2" at this point I want "prog1", to wait until "prog2" (does not exit) but gets to a certain point in its process, so I will need to send a callback to "Prog1" I know I can use process.start to call the second program, and I can also wait until the program has exited, but what I cannot work out is how to wait until a call back is recieved and send that callback to prog1. Can anyone help please c# or vb.net I don'y mind.
-
Hi, I have two .net application (exe). Prog1 and Prog2 What I would like to do is run the first program (prog1) and then from "prog1" run the second prgram "prog2" at this point I want "prog1", to wait until "prog2" (does not exit) but gets to a certain point in its process, so I will need to send a callback to "Prog1" I know I can use process.start to call the second program, and I can also wait until the program has exited, but what I cannot work out is how to wait until a call back is recieved and send that callback to prog1. Can anyone help please c# or vb.net I don'y mind.
There maybe a more politically correct solution but... You could instead of using process.start, use loadassembly. Then either pass a delegate into proj2 and have it invoke it when it gets to the point you refer to or you could also use an event to trigger the action (your choice obviously).
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
-
Hi, I have two .net application (exe). Prog1 and Prog2 What I would like to do is run the first program (prog1) and then from "prog1" run the second prgram "prog2" at this point I want "prog1", to wait until "prog2" (does not exit) but gets to a certain point in its process, so I will need to send a callback to "Prog1" I know I can use process.start to call the second program, and I can also wait until the program has exited, but what I cannot work out is how to wait until a call back is recieved and send that callback to prog1. Can anyone help please c# or vb.net I don'y mind.
Not sure if this will work but... could you not make prog1 com visible and then expose the function in prog1 that you want prog2 to call when it gets to a specific point in its processing? I've used this process to get jscript code sitting behind an Internet Explorer page to call a function in my vb.net app
-
Hi, I have two .net application (exe). Prog1 and Prog2 What I would like to do is run the first program (prog1) and then from "prog1" run the second prgram "prog2" at this point I want "prog1", to wait until "prog2" (does not exit) but gets to a certain point in its process, so I will need to send a callback to "Prog1" I know I can use process.start to call the second program, and I can also wait until the program has exited, but what I cannot work out is how to wait until a call back is recieved and send that callback to prog1. Can anyone help please c# or vb.net I don'y mind.
Hi, You need interprocess synchronization! There are several methods, but as I'm not an expert at this I'll just give one simple and possibly naive example using a named mutex. Process1:
using System;
using System.Diagnostics;
using System.Threading;
static void Main() {
String mutexName = Guid.NewGuid().ToString();
Process p = Process.Start(@"Process2", mutexName);
Console.WriteLine("Waiting for Process2 to create the mutex {0}", mutexName);
Mutex m = null;
do {
try {
m = Mutex.OpenExisting(mutexName);
} catch (WaitHandleCannotBeOpenedException) {
Thread.Sleep(50);
}
} while (m == null);// wait for mutex release
Console.WriteLine("Process1 has opened the mutex, waiting for release");
if (m.WaitOne(20000)) {
Console.WriteLine("Mutex was released");
} else {
Console.WriteLine("Wait period exceeded");
}
Console.WriteLine("Press enter to exit");
Console.ReadLine();
}Process1 starts Process2 passing the desired name of the synchronisation object. Process1 then polls until the Mutex has been created by Process2. Process1 can now wait for Process2 to release the Mutex. Process2:
static void Main(String[] args) {
Console.WriteLine("Process2 created mutex {0}", args[0]);
Mutex m = new Mutex(true, args[0]);
Console.WriteLine("Process2 simulating work for 5 seconds ...");
Thread.Sleep(5000);
m.ReleaseMutex();
Console.WriteLine("Process2 released mutex ...");
Console.WriteLine("Process2 doing something else ...");
Thread.Sleep(5000);
Console.WriteLine("Press enter to exit");
Console.ReadLine();
}There are several articles here on CodeProject. Try searching for interprocess communication or synchronisation. Alan.
-
Hi, You need interprocess synchronization! There are several methods, but as I'm not an expert at this I'll just give one simple and possibly naive example using a named mutex. Process1:
using System;
using System.Diagnostics;
using System.Threading;
static void Main() {
String mutexName = Guid.NewGuid().ToString();
Process p = Process.Start(@"Process2", mutexName);
Console.WriteLine("Waiting for Process2 to create the mutex {0}", mutexName);
Mutex m = null;
do {
try {
m = Mutex.OpenExisting(mutexName);
} catch (WaitHandleCannotBeOpenedException) {
Thread.Sleep(50);
}
} while (m == null);// wait for mutex release
Console.WriteLine("Process1 has opened the mutex, waiting for release");
if (m.WaitOne(20000)) {
Console.WriteLine("Mutex was released");
} else {
Console.WriteLine("Wait period exceeded");
}
Console.WriteLine("Press enter to exit");
Console.ReadLine();
}Process1 starts Process2 passing the desired name of the synchronisation object. Process1 then polls until the Mutex has been created by Process2. Process1 can now wait for Process2 to release the Mutex. Process2:
static void Main(String[] args) {
Console.WriteLine("Process2 created mutex {0}", args[0]);
Mutex m = new Mutex(true, args[0]);
Console.WriteLine("Process2 simulating work for 5 seconds ...");
Thread.Sleep(5000);
m.ReleaseMutex();
Console.WriteLine("Process2 released mutex ...");
Console.WriteLine("Process2 doing something else ...");
Thread.Sleep(5000);
Console.WriteLine("Press enter to exit");
Console.ReadLine();
}There are several articles here on CodeProject. Try searching for interprocess communication or synchronisation. Alan.
thank you very much , this is exactly what i need, excellent thanks