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#?
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.