Hi, i have a problem making my program share infos with his clone... Let me explain :)
I execute my program twice, and i want it to share text like a messenger (on a single computer) and the problem is, i don't want it to be one program with 2 forms, but 1 program running severeal times (2 or more)
How do i get the text from the "textbox_send" in the "textbox_recieve" of the other programs?
The main problem is that i can't figure out how to connect a program with itself, but not really "itself" :p

Can anyone help me?
Thanks
(If someone can't understand what i'm trying to say, tell me and i'll try to explain it better :] )

What are you trying to do exactly?

quick solution can be sharing common files to read and write data.

Looks like System Messaging is what you want. Have a look at the following code

'for more details please see
'http://www.informit.com/articles/article.aspx?p=23273

'For this code to work you must enable Microsoft Message Queue (MSMQ) Server
'Under Windows 7, go to Control Panel -> Programs and Features then click on
'"Turn Windows Features on or off" in the left panel. Select the box labeled
'Microsoft Message Queue (MSMQ) Server

Imports System.Messaging    'add reference to System Messaging (.NET tab)   

Public Class Form1

    'only private queues are available unless you are on a domain

    Const QNAME = ".\Private$\myQueue"
    Private myQueue As MessageQueue

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        'create the queue if it does not exist

        If Not MessageQueue.Exists(QNAME) Then
            MessageQueue.Create(QNAME, False)
        End If

        'get a reference to the queue and set the formatting

        myQueue = New MessageQueue(QNAME, False)
        myQueue.Formatter = New BinaryMessageFormatter

    End Sub

    Private Sub btnSend_Click(sender As System.Object, e As System.EventArgs) Handles btnSend.Click

        myQueue.Send("this is my message queued at " & Now())

    End Sub

    Private Sub btnReceive_Click(sender As System.Object, e As System.EventArgs) Handles btnReceive.Click

        'if there is no message in the queue then the program will wait
        'here until a message is available.

        Dim s As String = CType(myQueue.Receive.Body, String)
        MsgBox(s)

    End Sub

End Class

Build the application using the above code. First try running just one instance. Do a send, then do a receive. Now try running two instances. Do a send from one, then a receive from the other. Now try clicking send twice, then receive twice. If you click Receive more times than you click Send then the program will wait for a message. You can test this by running two instances. It gets fancier than this (you can send objects as easily as you send strings) but I haven't played with it to any extent.

I hope this helps. Thanks for the interesting question.

Ok, let's try to explain it again, without the example... (looks like people are just refering to it)
Please forget everything about the "Messenger thing" :)

What i'm trying to do, is a simple program where i have 2 textboxes, and a button.(there is more but no need to say for resolving my problem)
When i write text in the 1st textbox and click the button, it will be written in the 2nd textbox.
Now, when i run this program more than once, i want the text to be written in the 2nd textbox of the others programs.
Sorry for the bad explaination i gave you before, hope it's better :)
And thanks to everyone who tried to help me, even if it haven't resolved my problem ;)

Edited 4 Years Ago by Nan0_Zor: bad grammar

You are sharing data between two programs and I dont think there is no direct way to do this.

In order for that to happen the two instances have to have some type of communication. As was pointed out earlier, this could be through something as simple as a shared file, however, this is not a good method because it requires constant polling for file changes and coordination of file access. Another option is a named pipe but I think the simplest will be the MessageQueue although I don't know how you can make this run asynch without introducing timeouts and polling. Why does it have to be two copies of one program? Why not just use one program and have it display two identical forms? That way, changes to the textbox on one form can be automatically propogated to another on the second form.

Thanks for your answer, i wanted to have 2 or more copies of the program running, to learn how to do it, and then be able to link 2 programs, looks like i'm going to make a menustrip with an option to generate more forms.
Thank you all for your time spent to understand and solve my problem.

This question has already been answered. Start a new discussion instead.