问题
I'm developing a Windows Service in C#. One of my requirements is to get some user input: to present some options and let them select one; based on their choice, the service should perform an associated operation. Is it possible to get user input in a Windows Service, with C#?
回答1:
No, a Windows Service is not designed for that. You would need to use a desktop or web application. If there is a good reason to use a service, you would need to create an application and have it send or communicate the input to the service.
回答2:
I would write a separate application that manages the options in a database, a user can update this database in which the service also connects to, depending on these values the service should act accordingly
回答3:
No, it's not possible. You should create another windows app (for example winforms or WPF) and communicate with service and send user input. You can do communication via WCF.
回答4:
You can use ServiceBroker to Queue Userinput messages and dump the result in another Queue against the UserId or unique user key.
回答5:
Like others have said this is not possible. A Windows service, as the name implies is a Service. If you want to send data to a Windows Service, you can either do so through the ServiceController Class (from another application) or if you're feeling particularly adventurous though WCF.
Why are you developing this as a service?
回答6:
Yes, It is possible to get inputs from mouse and keyboard from windows service. This does not mean that, we can directly interact with the windows service. Service code can read the last keyboard input and mouse position and other events. for example, service can read the current mouse position using Cursor.Position
property.
来源:https://stackoverflow.com/questions/13702160/is-it-possible-to-get-user-input-in-windows-service-c-sharp