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)

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


Attachments

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.

Note You need to log in before you can comment on or make changes to this bug.