Reputation: 1842
I am creating a project with a DLL that will have one public method Process();
There will be a service that will call this method every three minutes.
There will also be a console application that will call this method.
If the method is currently running, how can I keep the console application from calling it while the service is already running it?
Upvotes: 3
Views: 386
Reputation: 17428
You could use a named mutex to prevent callers from calling the same method.
Addiotional note:
You may run into permission issues regarding the named mutex if the service ends up creating it and it running as an administrator, your console app may not have permission to access the mutex unless you set the appropriate permissions on the mutex.
Upvotes: 1
Reputation: 10400
You should consider using a Mutex. Here is an article with some detail from MSDN: http://msdn.microsoft.com/en-us/library/hw29w7t1(v=vs.100).aspx
Upvotes: 1
Reputation: 70369
You will need to setup some sort of IPC - for example a global mutex used within that method to signal is running/not running currently would solve that problem (as long as both are running on the same machine that is)...
Upvotes: 4