0

Is it possible to somehow notify a running process from the "outside"?

I have a C# program that theoretical runs forever. And I would like to notify it to trigger some action manually. It would be best, if this solution is possible on Windows and Linux (mono).

EDIT:

  1. The solution should work without a user interface
  2. My program is, as for now, a part of web service. On initializing, a new Theread is created, which uses the Task class to stay alive
Leifb
  • 370
  • 7
  • 20
  • More context technical information please – miltone Jan 25 '16 at 12:30
  • 1
    User may click button, another process may own named mutex (windows), network command received... Can you be more specific, don't be shy, tell us what exactly you want to do. – Sinatr Jan 25 '16 at 12:30
  • "A program", console app? windows service? windows forms?... – Alexander Derck Jan 25 '16 at 12:34
  • If you want to run only one instance: http://stackoverflow.com/questions/93989/prevent-multiple-instances-of-a-given-app-in-net – Andrey Burykin Jan 25 '16 at 12:35
  • There are a huge number of ways a process can listen for notifications. You'll need to narrow things down far more. Eg. what kind of notifications: local or remote; from a user or another program? – Richard Jan 25 '16 at 13:42

1 Answers1

5

Take your forever-running-process and let it provide a webservice other processes can call.

You might use any cross-plattform webservice framework like WebApi or ServiceStack to achieve this via HTTP calls. This will even work over the internet (if the machines can reach each other).

There are dozens of approaches. You could also use named pipes for example, or put commands into a database (the other process has to query regularly) or - if you're fearless enough - write/read files to communicate. Be creative ...

Community
  • 1
  • 1
Waescher
  • 5,361
  • 3
  • 34
  • 51
  • So, I just edited my post. I think that it might be confusing when there are urls which sould be accessible to the outside and others thet should only work internally – Leifb Jan 25 '16 at 12:38
  • 2
    Why? Depending on the triggers you want to implement (I assume the new ones will be the ones you called "internally"), you could make one base URL for your internal calls like "/maintenance/triggers/" and call them like "/maintenance/triggers/1/start" or anything like that. – Waescher Jan 25 '16 at 12:40
  • That sounds actually pretty good. And the named pipes are also helpful, when I may consider splitting the web service and my "program". Thanks! – Leifb Jan 25 '16 at 12:44
  • You're welcome. Would you mind to accept the answer for all the future users coming to this question? ... and for my ego of course ;) – Waescher Jan 25 '16 at 12:53
  • Ups, I though this is only possible after some days... Of cause, it's the right answer :) – Leifb Jan 25 '16 at 12:59