Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Process.start wait for a callback

Process.start wait for a callback

Scheduled Pinned Locked Moved Visual Basic
csharphelptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    coolpjmartin
    wrote on last edited by
    #1

    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.

    N R A 3 Replies Last reply
    0
    • C coolpjmartin

      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.

      N Offline
      N Offline
      nlarson11
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • C coolpjmartin

        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.

        R Offline
        R Offline
        richardw48
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • C coolpjmartin

          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.

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #4

          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.

          C 1 Reply Last reply
          0
          • A Alan N

            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.

            C Offline
            C Offline
            coolpjmartin
            wrote on last edited by
            #5

            thank you very much , this is exactly what i need, excellent thanks

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups