Search code examples
c#socketswcfservicepipe

Tray app and service and normal win forms all altogether c#


I'm developing an application and some how it's getting complicated. I wanted to know the best principles in my case and if I'm going into the right direction.

consider this:

  1. I have a(some) physical device(s) with IP connection

  2. I have a Windows Forms application (App) that I can have many instances of it in different processes and it should connect to one of physical devices and do some actions.

  3. I want to manage connection to devices with a service.

  4. I want to manage devices configuration (that is writing and reading to/from a XML file) with another service and app needs to ask some info of devices from this service. and obviously it should apply configuration via connection service.

  5. I want to have a tray application to direct access to these services and configurations.

I assumed many instances of my App like many text editing applications that want to print the text via a/some printers. and that tray application that i want is like the tray icon of printer that shows the queue and every thing is like that completely.

what is the best way to handle the inter-communication between my services and apps? WCF maybe? Socket? Named-Pipe? I want the easiest and fastest way, and the less coding is the most easy and fast.

and if you have any suggestion in every part of my scenario, I'm glad to know. tnx.

Edit 1: I can forget about services and put their functionality in tray application. Is it a good choice?


Solution

  • I tried some different ways and the best one which worked for me was something like the picture below. Main App = the App I mentioned in the question Help App = a new App that can minimize to the tray

    • I used WCF with TCP connection in it - http connection is very slow for realtime apps
    • I used TCP connection between Help App and devices
    • I used IO-Read/Write for XML config files

    and if I want explain the way I used WCF, I should say it is like a chat service that applications talk to each other with predefined messages (enumeration) and do actions when a message is received or send a message in answer. asynchronous messaging had better result in order to not having a deadlock or waiting.

    and by the way I created the WCF host in a windows service.

    enter image description here