Accessing Windows service from a windows app
Hi All,
I've a desktop application, which has a local db, and a master copy of that db is on server, so we need to synch.
For synchronization we've made a separate Windows service, so that it can run separately from the application and synch. and when the application starts it should stop, so that synching of the tables dont disturb the user interface.
Now that Windows Service needs to know few things from the main application, like on the event when the user Enables his sharing in the application, I need to tell this to the service, and pass on the database credentials to it from the main application, which it can use for synching, prior to this event it'd do nothing.
1. How can I stop the service, when the application starts?
2. For passing info from application to Service, how do I set it?, One idea thats in my mind, is have a public method in the Service class like
public bool SetProperties(string DbLogin, string, DbPassword, string DBName)
{
Properties.Settings.Default.DBLogin = DBLogin;
Properties.Settings.Default.DbPassword= DbPassword;
Properties.Settings.Default.DBName= DBName;
}
and call it on the EnableSharing event from the application, but I am confused on how to get the active instance of the Service, I can add the reference of the dll of Service, but would that give me access to the service, which is currently stopped?
3. Is there a better way to do what I am trying to do?
Thanks for your time,
Regards,
Sajid.
|