6632

Determine if a Form from another project is open

Question:

My c# WinForm solution contains several projects including an Admin project with several forms and a User project with several forms. I want my user forms to behave differently when specific admin forms are open.

How can the user forms tell when admin forms are open?

All forms have no 'this.Text' value (all these values are null).

When I loop through all forms identified by 'FormCollection fc = Application.OpenForms', it does not show the forms from the other project; it seems to only show the forms from the same project.

Also, all the admin forms run from one .exe file and all the user forms run from another .exe file.

Any help is appreciated.

Answer1:

Use <a href="http://msdn.microsoft.com/en-us/library/c41ybyt3.aspx" rel="nofollow">Mutex</a> class for that scope.<br /> Mutex is a Windows kernel object that has an unique identifier for a Windows computer.

public class Form2 : Form { Mutex m; protected override void OnShown(EventArgs e) { base.OnShown(e); m = new Mutex(true, "Form2"); } protected override void OnClosed(EventArgs e) { base.OnClosed(e); m.ReleaseMutex(); } } public class Form3 : Form { bool form2IsOpen; public Form3() { try { Mutex.OpenExisting("Form2"); form2IsOpen = true; } catch (WaitHandleCannotBeOpenedException ex) { form2IsOpen = false; } } }

Answer2:

What you need is a way of Inter Process Communication.<br /> There are many ways to achieve this most of the will be overkill for your situation.<br /> I this the best way is your case is to have a file that the admin process will write to and the other processes will read from and infer the state of the admin process.

Recommend

  • Need to access the other winform in c#
  • Iterate through Windows forms and close them?
  • ASP.NET MVC - Reusing Action Behaviors
  • Python create word plot between two lists in matplotlib to show list commonality
  • Can i have One form tag inside Another in ASP.net MVC RC2
  • Python switch case
  • How to process many form input fields using ASP.NET MVC
  • get the content when the div does not have the id of the div … only has the class
  • Java Save and Load Program's State
  • Android studio 3.1 rebuild project each time to see the changes
  • Is there a OpenForms Property in WPF?
  • ASP.NET MVC C#: Object reference errors when going to view record details
  • Socket.io on socket disconnect
  • Pass data to a existing form
  • Hakyll says “Dependency cycle detected: …”
  • Mocking Non-Standard Events in F# Foq
  • Configuring Ninject
  • How do I change the kernel/python version for iPython?
  • triggering user space with kernel
  • aapt.exe'' finished with non-zero exit value 1
  • Javascript, Regex - I need to grab each section of a string contained in brackets
  • Tamper-proof configuration files in .NET?
  • Code in Job's Script Block after Start-Process Does not Execute
  • Spring Data JPA custom method causing PropertyReferenceException
  • C# - Serializing and deserializing static member
  • Sending data from AppleScript to FileMaker records
  • Running a C# exe file
  • Why winpcap requires both .lib and .dll to run?
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • How to include full .NET prerequisite for Wix Burn installer
  • KeystoneJS: Relationships in Admin UI not updating
  • AngularJs get employee from factory
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Is it possible to post an object from jquery to bottle.py?