0

In VB6 there is a Form event called LinkExecute witch I can use to link tow projects together. For example I create project A with a button and link it with project B witch has a textbox when I click on the button on project A the textbox in project B changed.

To simplify the idea it link the tow projects and make one of them listen to the other events and when a specific event occur on the main project the listener fire an event locally on the listener project.

Both projects are WinForms and run on the same machine.

Project A

Private Sub Command1_Click()
    On Error Resume Next

    Text1.LinkTopic = "Project1|SYSTEM"
    Text1.LinkItem = "TEXTSource"
    Text1.LinkMode = vbLinkManual
    Text1.LinkRequest ' "Hello World"

    Text1.LinkExecute "Hello World"

    DoEvents
End Sub

Public Sub Form_Load()

End Sub

Project B

Private Sub Command1_Click()
    Label1.Caption = Val(Label1.Caption) + 1    
End Sub

Private Sub Form_LinkClose()
    List1.AddItem "Form_LinkClose"
    Command1_Click
End Sub

Private Sub Form_LinkError(LinkErr As Integer)
    List1.AddItem "form_LinkError"
    Command1_Click
End Sub

Private Sub Form_LinkExecute(CmdStr As String, Cancel As Integer)
    List1.AddItem "Command " & CmdStr & " has been received"
    Cancel = False
    Command1_Click
End Sub

Private Sub Form_LinkOpen(Cancel As Integer)
    List1.AddItem "Form_LinkOpen"
    Cancel = False
    Command1_Click
End Sub

Private Sub Form_Load()
    List1.Clear
    Command1_Click
End Sub

Private Sub PictureSource_LinkClose()
    List1.AddItem "PictureSource LinkClose"
    Command1_Click
End Sub

Private Sub PictureSource_LinkError(LinkErr As Integer)
    List1.AddItem "PictureSource LinkError: Error = " & LinkErr
    Command1_Click
End Sub

Private Sub PictureSource_LinkNotify()
    List1.AddItem "PictureSource LinkNotify"
    Command1_Click
End Sub

Private Sub PictureSource_LinkOpen(Cancel As Integer)
    List1.AddItem "PictureSource LinkOpen"
    Command1_Click
End Sub

So what is the equivalent to LinkExecute in C# or how can I do the same in C#?

GSerg
  • 76,472
  • 17
  • 159
  • 346
AnAs51993
  • 136
  • 1
  • 12
  • 1
    What's the question? Showing some code would help – Jeremy Thompson Oct 31 '16 at 03:25
  • oh ^^ what is the equivalent to LinkExecute in C# or how I can do the same in c# I have no Idea about vb6 but my coworker show me example in vb6 I well ask him for code tomorrow – AnAs51993 Oct 31 '16 at 03:26
  • I added code sample – AnAs51993 Oct 31 '16 at 17:24
  • 1
    Related: [Please feel free to stop using DDE](https://blogs.msdn.microsoft.com/oldnewthing/20070226-00/?p=27863) – GSerg Oct 31 '16 at 17:31
  • @GSerg I did not start using it to feel free to stop using it^^, I read the entire discussion but I did not get the point?? how it answer my question?? I know it is an old method so what is the equivalent,or the replacing methods for it? – AnAs51993 Oct 31 '16 at 17:57
  • 1
    @AnAs51993 The answer to your question is "please use any other non-deprecated interprocess communication mechanism available in .NET". There are many and you might find that some look better than other to you. The [answer below](http://stackoverflow.com/a/40336286/11683) gives an overview of your choices. You can find more by searching for "interprocess communication". There is no single definitive answer for What to use instead of DDE. – GSerg Oct 31 '16 at 18:08

1 Answers1

2

DDE is an older interprocess communication protocol that relies heavily on passing windows messages back and forth between applications. Other, more modern and robust, techniques for interprocess communication are available like Inter-process communication In order for two projects to exchange events, they must agree on how these events are communicated. There are many different ways of doing this, and exactly which method to use may depend on architecture and context.

You can also look for some of the common techniques used like files(Reading from a common file), Named Pipes, Queues (MSMQ), Use TCP/UDP socket connection, Use WebServices, WCF or Restful Web Service, Remote Procedure Calls (RPC), Reading from a common entry in a db. (Not recommended), window messages and shared memory. As you are implementing both applications yourself you can chose to use any IPC method you prefer. Network sockets and higher-level socket-based protocols like HTTP, XML-RPC and SOAP, as they allow you do run the applications on different physical machines as well.

I would prefer to use MSMQ as it would preserve the ability of having processes in different machines

  1. MSMQ allows you not to lose messages (in case RECEIVER is down)
  2. MSMQ allows you to have processes in same machine or in different machines
  3. Windows service give you the ability to start/stop the processes easily
  4. Windows service can me monitored my SNMP and in general they integrate easily with windows admin tools.

Edit

The Reference for the answer has been taken from Listen for events in another application, Send/Receive message To/From two running application and NDde: CodePlex

Community
  • 1
  • 1
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • I am aware of some of the methods you mention above but what interest me about LinkExecute is that you don't need to set timer to continuously read a common file or db field or any middle communication method as long as the tow projects runs together the communication is on – AnAs51993 Oct 31 '16 at 03:58
  • I didn't downvote you. was it me?? because it does not show me an orange arrow ?? I red the link about FileSystemWatcher and it interest me actually and I am reading and searching about it now thanks for it,I well vote you up when I am done searching and collecting information about it ,usually I vote for answers when I close the question,thanks for you help. – AnAs51993 Oct 31 '16 at 04:19