Bug 33235 - Service does not stop when ServiceBase.Stop() is called during ServiceBase.OnStart()
Summary: Service does not stop when ServiceBase.Stop() is called during ServiceBase.On...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 4.8.0 (C9)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-08-19 15:22 UTC by Daniel Schultze
Modified: 2017-09-06 16:55 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 33235 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Daniel Schultze 2015-08-19 15:22:48 UTC
Service does not stop when ServiceBase.Stop() is called during ServiceBase.OnStart(). A service will stop in Windows/.net Framework when ServiceBase.Stop() is called during ServiceBase.OnStart(). In mono an exception must be thrown to Fail during startup. If this is intended would you please clarify why that is?

	class Program
	{
		static void Main(string[] args)
		{
			WindowsStoppingService myService = new WindowsStoppingService();
			ServiceBase.Run(new ServiceBase[] {myService});
		}
	}

	partial class WindowsStoppingService : ServiceBase
	{
		public WindowsStoppingService()
		{
			InitializeComponent();
		}

		protected override void OnStart(string[] args)
		{
			Stop();
			// throw new Exception("Does exception stop a service?");
		}

		protected override void OnStop()
		{
			using(StreamWriter sw = File.AppendText("StoppingService.log"))
			{
				sw.WriteLine("{0} OnStop()", DateTime.Now.ToLongTimeString());
			}
		}
	}
Comment 1 Daniel Schultze 2015-08-25 18:58:43 UTC
I tested the service on 4.0.3.20 and it has the same problem.
Comment 2 Daniel Schultze 2017-04-12 17:15:30 UTC
This continues to be an issue on mono versions 4.2.1 and 4.8.0 on Ubuntu 16.04.2 LTS.