Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Windows Service stopping immediately
Message
De
03/09/2013 20:41:54
 
 
À
02/09/2013 23:31:41
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01581778
Message ID:
01582009
Vues:
42
>For this one, I have to say, I have no idea on how to rearchitect the design so it would be called. Have you ever done something like that?

No, because as I said in my other post, I have only one class sub-classed from ServiceBase and that is in the EXE. I have a feeling that you're not understanding what I'm trying to tell you about how to architect this. I don't know what else to say except to look closely again at what I posted earlier. Let me try to elaborate with just a little more code. This is basically what I posted before, but I've added some comments and other sample code:
// Remember ... this is the ONLY class that I inherit from ServiceBase, and it lives in the EXE
public partial class MyService : ServiceBase
{
	// These classes are defined elsewhere, in my Framework DLLs
	// They are not sub-classed from ServiceBase, in fact they are not sub-classed at all
	// They are just plain old classes
	static MyTransferClass Transfer;
	static MyHostClass Host;

	public MyService()
	{
		this.CanStop = true;
		this.CanShutdown = true;
		this.CanPauseAndContinue = false;
	}
	protected override void OnStart(string[] args)
	{
		// startup code here
		Transfer = new MyTransferClass();
		Host = new MyHostClass();

		Transfer.Start();
		Host.Start();

		//Console.WriteLine("Done With OnStart");
	}
	protected override void OnStop()
	{
		// stop code here
		if (Host != null)
			Host.Stop();
		if (Transfer != null)
			Transfer.Stop();
	}
	protected override void OnShutdown()
	{
		// TODO: There may be a bug in the .NET Framework in that this method
		// is not being called on system shutdown for SYSTEM account services.
		// Not sure when/if it will be fixed, but I'm putting code here to stop
		// stuff on the off-chance that it will be called eventually.

		// stop code  here
	}

	// These 2 methods are only used when not runnning as a Service, for testing from a Console window.
	public void Start()
	{
		this.OnStart(null);
	}
	public void Stop()
	{
		this.OnStop();
	}
}
Is this helping any????

~~Bonnie





>>I'm glad you finally got it working, Michel!
>
>BTW, this has created a downsize effect. Lets take a look back at the main class:
>
>
>Imports System.ServiceProcess
>
>Public Class Main
>    Inherits WindowsService
>
>    Public Sub New()
>    End Sub
>
>    Shared Sub Main()
>
>        ' If this from the Windows Service
>        If Not Environment.UserInteractive Then
>            Dim loWindowsService As ServiceBase()
>            loWindowsService = New ServiceBase() {New WindowsService()}
>            ServiceBase.Run(loWindowsService)
>        Else
>            oWindowsService = New WindowsService()
>            oWindowsService.Start()
>            Console.ReadLine()
>            oWindowsService.Stop2()
>        End If
>
>    End Sub
>
>    Public Overrides Function Initialize() As Boolean
>        oApp.cMemberTable = "Member"
>        Return True
>    End Function
>
>
>As you can see, I have an Overrrides on Initialize(). This does not get called anymore. It took me a while to find a weird situation and this was due to this. This main class inherits from WindowsService. But, because the Main() method is instantiating an instance of the WindowsService class on its own, this cancelled the default behavior of the WindowsService base class which contains something like this:
>
>
>    ' Allow the client to set up custom code in the initialization
>    Public Overridable Function Initialize() As Boolean
>        Return True
>    End Function
>
>
>For this one, I have to say, I have no idea on how to rearchitect the design so it would be called. Have you ever done something like that?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform