For the service to be useful, OnStart and OnStop should both be implemented in your service class. Process initialization arguments for the service in the OnStart method, not in the Main method. The arguments in the args parameter array can be set manually in the properties window for the service in the Services console. The arguments entered in the console are not saved; they are passed to the service on a one-time basis when the service is started from the control panel.
GetCommandLineArgs ;. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info. The Stop command returns and throws an exception. OnStop is expected to be overridden in the derived class. For the service to be useful, OnStart and OnStop should both be implemented in your service class.
Skip to main content. This browser is no longer supported. How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more.
Windows service OnStop wait for finished processing Ask Question. Asked 7 years, 10 months ago. Active 4 years, 5 months ago. Viewed 26k times. NET 4. The service is following the scheme of the code snippet below: Using a timer Executes some desired operation every couple of minutes.
The process takes about 10 minutes to complete I use a single thread in the service What I am worried about is that if somebody stops the service via the management console, it might be just during the process that the service is doing. What is the best way forward then, also considering the code snippet below? Thanks all! SourceExists DAL. Start ; EventLog. WriteEntry DAL. Message , EventLogEntryType.
I have actually been playing with this recently. While you can request more time using RequestAdditionalTime , There is no way to get windows to give you a full 10 minutes to stop. I believe the most you can get is 2. I already look for this function, but I would like the stop is performed at the end of the process no matter how long it takes to execute.
I understand that. Unfortunately, windows won't allow it. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy. Thank you. Microsoft makes no warranties, express or implied, with respect to the information provided here.
0コメント