Reputation: 1719
I have an outlook plugin and a desktop application.I have implemented the same synchronization process in both the applications.But, I don't want to allow the user to run the synchronization process from both application simultaneously.So, when a sync is running and user tries to start the sync from another application. He/She is shown a message that sync is already running and the sync request is aborted.To implement this,I was thinking of creating a file and whenever an application starts a sync.It creates an entry in that file.So that if a user then tries to start sync from the second application, then first the file is checked for the entry and if entry exists, then the request is aborted.Is there any other way to do this?
Upvotes: 4
Views: 1843
Reputation: 15772
You don't want IPC. IPC reduces the problem to the two generals problem, as even with IPC, you would have a race condition.
What makes more sense is to create a third process, a service that is responsible for storing and syncing the data. I shall call this service the database.
Then the outlook plugin and the desktop application can merely connect and grab data from this database as they want.
They can also request a synchronization whenever they want, in the knowledge that the database service will only run one synchronization at any one time.
Finally, there are many free products that are out there that will give you this functionality, without you writing it explicitely, for example, you could have used a CouchDB service for data sync/storage.
Upvotes: 2
Reputation: 1802
if you have control over both of these application then you can use Named pipes in order to start communication between them. Named Pipe is the best for interprocess communication in windows which works with server client architecture.and there is .net Wrapper around named pipe it will greatly simplify the whole process.
a code from there.
Server Code
var server = new NamedPipeServer<SomeClass>("MyServerPipe");
server.ClientConnected += delegate(NamedPipeConnection<SomeClass> conn)
{
Console.WriteLine("Client {0} is now connected!", conn.Id);
conn.PushMessage(new SomeClass { Text: "Welcome!" });
};
server.ClientMessage += delegate(NamedPipeConnection<SomeClass> conn, SomeClass message)
{
Console.WriteLine("Client {0} says: {1}", conn.Id, message.Text);
};
// Start up the server asynchronously and begin listening for connections.
// This method will return immediately while the server runs in a separate background thread.
server.Start();
and Client Code
var client = new NamedPipeClient<SomeClass>("MyServerPipe");
client.ServerMessage += delegate(NamedPipeConnection<SomeClass> conn, SomeClass message)
{
Console.WriteLine("Server says: {0}", message.Text);
};
// Start up the client asynchronously and connect to the specified server pipe.
// This method will return immediately while the client runs in a separate background thread.
client.Start();
hopefully it will help you.
Upvotes: 4