I made single instance app, but my problem is, I don't know how to get the first opened FormMain instance and update the form TextBox! Could you help me?
static void Main(string[] args)
{
bool result;
Mutex mutex = new System.Threading.Mutex(true, "unique_name", out result);
if (!result)
{
**/*
CALL OPENED FORM INSTANCE AND UPDATE TEXTBOX
*/**
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true);
Application.Run(new FormMain(args));
GC.KeepAlive(mutex);
}
You can use named pipeline interprocess communication like that:
Usings
Static variables
Application unique identifier
Check only one instance and init the server
Create the server
Anwser to a request
Test
Usage
You can create as string commands as needed.
For example it allows to pass command line arguments from a process just started to the actual running process.
Also you can improve this simple behavior to have a more complex system, to use a classes framework instead of string commands.
For your application you should be able to use:
If you modify a WinForm control you must to synchronize with the main UI thread:
How do I update the GUI from another thread?
How to access a WinForms control from another thread i.e. synchronize with the GUI thread?
Some links
PipeStream
Full Duplex Asynchronous Read/Write with Named Pipes (CodeProject)
Inter Process Communication (C# Vault)
WCF Comparison with Web Services and .NET Remoting (CodeProject)
Socket Programming In C# (C-SharpCorner)
Socket Programming in C# (GeeksForGeeks)
Simple Client-server Interactions using C# (CodeProject)