Click here to Skip to main content
16,023,339 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I have application use Mdi this form reads test file and I want to read each file in his own form.

Example:
I'll open txt file name 1.txt my project will open this file in form1 (we are now in Process no 1). After that if we open other txt file by "Open With" the file will open but in other Process.

I'm using this code to show message if second Process exist:
C#
if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
{
       MessageBox.Show("application is already running");
}

But what I want is not to show the Message but to open the second file in form 2 in Process1.

I hope I'm clear.
Posted
Updated 25-Sep-10 2:35am
v2

1 solution

There are several options to use:

First you could use named pipes. If the application cannot connect this means that it is the first instance and will setup itself as server. Otherwise it will be a client to an already running instance and pass the related information.
http://www.switchonthecode.com/tutorials/interprocess-communication-using-named-pipes-in-csharp[^]

Second you could have a look at these methods of sharing data between processes.
A C# Framework for Interprocess Synchronization and Communication[^]

Third would be a solution you could implement without much hassle. (it's more than just the single-instance implementation)

Single-Instance C# Application - for .NET 2.0[^]

Good luck!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900