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. C#
  4. How to capture running instance of an application ?

How to capture running instance of an application ?

Scheduled Pinned Locked Moved C#
helptutorialquestion
2 Posts 2 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.
  • M Offline
    M Offline
    Mr Perfect
    wrote on last edited by
    #1

    Dear All, Please help me in solving my problem. I have a windows application called "CallProcess", in it I have two TextBoxes on the form. I also have a method called display(), In this method I am creating a File and writing the text entered in the textBox into the file. Following is the code snippet, public void Display() { StreamWriter sw = new StreamWriter(@"c:\shutdown.txt", true); sw.WriteLine(textBox1.Text); sw.WriteLine(textBox2.Text); sw.WriteLine("Data written after execution of textbox data"); sw.Close(); } Now I want to access this method in other windows application, I am writing the following code snippet, try { Process[] BPDProcesses = Process.GetProcessesByName "CallProcess"); foreach (Process BPDProcess in BPDProcesses) { Console.WriteLine(BPDProcess.HasExited.ToString()); string ModuleName = "CallProcess.exe"; string TypeName = "Form1"; string MethodName = "Display"; Assembly BPDAssembly = Assembly.LoadFrom BPDProcess.MainModule.FileName.ToString()); BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); Module[] BPDModules = BPDAssembly.GetModules(); foreach (Module BPDModule in BPDModules) { if (BPDModule.Name == ModuleName) { Type[] BPDTypes = BPDModule.GetTypes(); foreach (Type BPDType in BPDTypes) { if (BPDType.Name == TypeName) { MethodInfo[] BPDMethodInfo = BPDType.GetMethods(flags); foreach (MethodInfo BPDMethod in BPDMethodInfo) { if (BPDMethod.Name == MethodName) { try { Object obj = Activator.CreateInstance(BPDType);

    L 1 Reply Last reply
    0
    • M Mr Perfect

      Dear All, Please help me in solving my problem. I have a windows application called "CallProcess", in it I have two TextBoxes on the form. I also have a method called display(), In this method I am creating a File and writing the text entered in the textBox into the file. Following is the code snippet, public void Display() { StreamWriter sw = new StreamWriter(@"c:\shutdown.txt", true); sw.WriteLine(textBox1.Text); sw.WriteLine(textBox2.Text); sw.WriteLine("Data written after execution of textbox data"); sw.Close(); } Now I want to access this method in other windows application, I am writing the following code snippet, try { Process[] BPDProcesses = Process.GetProcessesByName "CallProcess"); foreach (Process BPDProcess in BPDProcesses) { Console.WriteLine(BPDProcess.HasExited.ToString()); string ModuleName = "CallProcess.exe"; string TypeName = "Form1"; string MethodName = "Display"; Assembly BPDAssembly = Assembly.LoadFrom BPDProcess.MainModule.FileName.ToString()); BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); Module[] BPDModules = BPDAssembly.GetModules(); foreach (Module BPDModule in BPDModules) { if (BPDModule.Name == ModuleName) { Type[] BPDTypes = BPDModule.GetTypes(); foreach (Type BPDType in BPDTypes) { if (BPDType.Name == TypeName) { MethodInfo[] BPDMethodInfo = BPDType.GetMethods(flags); foreach (MethodInfo BPDMethod in BPDMethodInfo) { if (BPDMethod.Name == MethodName) { try { Object obj = Activator.CreateInstance(BPDType);

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Mr Perfect wrote:

      But here I am getting the new instance of the application, the textbox data is null, I want the same data which was entered in the previous application

      http://en.wikipedia.org/wiki/Inter-process_communication[^]

      led mike

      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