I would like to develop a program (an agent) that will run on the user's desktop. It has to communicate with a web service periodically then if a state changes it will notify the user in a notification balloon.
Can I do a winforms or wpf project? (that will both communicate with the web service and notify the user)
Or should I do separately a windows service that will firstly communicate with the web service and then communicate with another standalone winforms app that will notify the user?
Thanks.
Periodically fetching status through service
You can implement an executable(Console) application which should have the logic to invoke the web service to fetch the status. You can use windows task scheduler to execute this exe periodically.
There are many task scheduler wrapper libraries are available, Use could use any of them based on your need.
Task Scheduler Managed Wrapper
Quartz Job Scheduler
Notifying user
If the status is changed then you can notify the user through any User interface, this can be WinForm or WPF application. When the exe which is initiated by the task scheduler finds a status change, it will execute the UI application that you have created to notify the user.
If you need only a single Form to notify the user then Windows Form should be enough unless you want to show any fancy UI using WPF.
Why Windows Service might not be a good choice
It's actually easy to use a windows service to periodically call the web service instead of using a Task scheduler, but the problem you will face with the windows service is that it can't easily communicate with user's desktop, that means it can't directly show/execute any User interface application on user desktop. You will end up writing a IPC(Inter Process Communication) mechanism to communicate with any UI application from windows service.
Related
I am trying to run an Exe on start of window service . In development mode it triggers exe and UI is visible once triggered . But after windows service installed , i am not seeing the UI but exe is running as background process. How to make UI visible for the tiggered exe from windows service.
Services do not display a user interface directly due to Session 0 isolation. So you'll need to rethink with a client-server-style separation of service processing from user interface.
The user-mode UI process will start when the user logs in and remain largely idle/hidden. It will establish an inter-process communication connection to the service and await orders in client-server fashion. If the server wants to "push" some kind of an alert to the client, it does so by notifying the user-mode application to display the user interface on its behalf.
I have developed an application which does periodical jobs. It runs as windows service in background and manages jobs. I want to trigger another application with GUI from service application when any error notification needs to be given to user. So after seeing err message user will give some response. So now service application (running as service) should do some work based on user response in GUI application (with interface). User response should be communicated to the service application.
So my requirement is
Application running as service should be able to trigger another application with GUI (its sufficient if triggering happens only when users are logged in)
Communication between an application running as service and application with GUI.
I saw many links about communication between service and application. Named pipes requires .net 3.5 and above, but I want my application to work in .net 2 alone. Writing to a txt file and reading it is last option for me as it is not the best method.
So how it can be done? Please give me ideas to start with.
I am developing an windows application using WPF and this application follows MVVM. My application displays the status of two Windows services. That is, if the application is open and the service is stopped, immediately the status needs to be changed in UI. Similarly if the application is open and the service is started, immediately the status needs to be changed in Application UI.Before, I never needed to handle windows services. So please help me.
You can use the ServiceController class to poll for the service status at intervals.
With this anyway you can't really have an immediate notification, there is a poll delay error. If you want something more accurate you should modify the services to send its status to a listener using some IPC mechanism.
I have a C# based windows exe using a WPF GUI. My GUI app. polls another window service every minute running on same machine for some updates. Can i expose a COM interface into my WPF GUI exe so that i can remove polling and instead window service make a COM call into the WPF GUI exe app to provide updates?
You probably could, but why COM? You could just as well use .NET communication technologies like Remoting or WCF.
That said, it's usually better to let the UI client initiate the communication to the Windows service and not the other way around. Mainly because you can have multiple client apps running (if more than one user is logged on to the machine).
I am trying to start a process programatically from windows service written in C#. i see my process having started in the task manager but i dont see its UI.
Any idea whats going on? i am running this on windows xp
clientProcess = new System.Diagnostics.Process();
clientProcess.StartInfo.FileName = system_drive_path + #"\sd\ud\ud.exe";
clientProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
clientProcess.Start();
Services don't have a desktop associated with them, so when you start the GUI application, it will not show up to the user.
You need to configure the service to have interaction with the desktop, then it will work. You can do this either diagrammatically in the service installer class
Or manually in the service properties windows, under the Log On tab.
You are not supposed to interact with the user from a service, including starting a process. This is actually actively disallowed in Vista and later, including services marked as 'interactive', for various reasons primarily security:
Important Services cannot directly
interact with a user as of Windows
Vista.
If you want to interact with the user session then you must have a process in the user session (eg. a tray icon application) that interacts with the service via an IPC protocol (net pipes, shared memory, messages etc).
Create a separate UI application that runs at session start up and that application can start your 'sd.exe' when asked so by the service.