Hi,
I have a question about passing a value/indicator between projects in DOTNET (VS2010 & C#). Overall these 2 projects create an application which continuously runs on users computers Windows XP, Vista, & Win 7). There is a main project and a Windows service project – the main project runs as an application when a user is logged into their computer, while the service project runs when the user logs out (when computer is back at the login screen). I need to pass a value/indicator between the main project and the service project, so that when the user logs off then if the value/indicator is set by the main project then the service project will recognise this, perform a task and reset/remove this so that it is only called one time (i.e. until the next time that the user logs into the computer and the value/indicators set again.
So far, I have been creating an files (XML) with a value, and saving this as a file on the (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) directory, so as to save this to the users MyDocuments directory. I had hoped to then access this when the user logs off (i.e. the last user to log off). However, I can't get the service part of my application to access this using the same special folder.
Overall, I am trying to find out if there is any way for a service project to access an XML file the MyDocuments (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) folder of the last user who was logged in, and then if the services project could modify this file to reset this value (as I just want this aspect called once when the user logs out). Alternatively, is there a different or better way to set a value/indicator from an application when the user is logged in, and then for a service project to access this when the user logs out and modify/reset it so that it isn't called continuously. From what I can see, Windows 7 seems to be tricky for permissions, so as to allow the service to both read a file and then modify it.
Hope this makes sense and any help/advice appreciated.

Mahesh ChandRank #1 · 393.3K reputationPosted Mar 31, 2011, 8:20 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Mar 31, 2011, 9:54 PM EDT
It depends on how much data needs to be exchanged. If no data needs to be exchanged other than the execution of the application, then you probably just need a synchronization facility such as a named event or a named mutex. I forget what they are called in managed code. If you think they will help then look for articles about them and if you have specific questions let us know.
VulpesRank #55 · 29.2K reputationPosted Apr 1, 2011, 1:26 AM EDT
However, if there is some overlap then I agree with Sam that you should be able to use named pipes (see http://msdn.microsoft.com/en-us/library/system.io.pipes.aspx for the .NET implementation) which I think are still able to communicate between different sessions under Vista and Windows 7.
Sam HobbsRank #107 · 20.5K reputationPosted Apr 1, 2011, 1:46 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Apr 1, 2011, 1:57 AM EDT
So the term "main project" is unclear; is it a console application or some other type of application?
If the service is truly a Windows Service then I don't understand "the service project runs when the user logs out". I am not real experienced with Windows Services but what you are saying seems to not be the way that Windows Services work.
VulpesRank #55 · 29.2K reputationPosted Apr 1, 2011, 2:55 AM EDT
I think the managed documentation for named pipes is good enough to do something simple like that but, if it isn't, then I can provide an example myself.
Stephen Clarke8 reputationPosted Apr 7, 2011, 6:26 AM EDT
Stephen Clarke8 reputationPosted Apr 7, 2011, 6:32 AM EDT