Best way to communicate between .Net applications?

If I manage both applications, then what is the best way to communicate between 2 exe written in VB.Net. For example, I want to delete an XML file from one application and pick it up with another, but I do not need a poll for the file. I heard about named pipes, but found it to be complicated. What is the most effective way to do this?

+3
source share
5 answers
+7
source

You do not need to poll for the file. Use FileSystemWatcher .

+4

- WCF. - WCF, .

+3

.NET 4 . . , , ( , WCF ).

+1

.exes, :

FileSystemWatcher .exe , "Commands.txt"

FileSystemWatcher1.Path = Application.StartupPath
FileSystemWatcher1.NotifyFilter=NotifyFilters.LastWrite
FileSystemWatcher1.Filter = "Commands.txt"
FileSystemWatcher1.EnableRaisingEvents = True

To track / stop monitoring, set the path and the EnableRaisingEvents property to True or False

This is the event raised when the file changed:

Private Sub FileSystemWatcher1_Changed(sender As System.Object, e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed
    'Open the file and read the content.
    'you can use your own commands
End Sub

This way you only get the event when the file changes, and you do not need to use timers or anything else.


In another .exe file, you just need to write the command or message that you want to send: This example records the current date and time, overwriting the file each time.

Dim Timestamp() As Byte = System.Text.Encoding.Default.GetBytes(Now.ToString)
Dim Fs As System.IO.FileStream
Fs = New System.IO.FileStream("Commands.txt", FileMode.Create, FileAccess.Write)
Fs.Write(Timestamp, 0, Timestamp.Length - 1)
Fs.Close()

Done!

0
source

Source: https://habr.com/ru/post/1740607/


All Articles