views:

8

answers:

1

How do we specify LoaderOptimizations when we are building a Windows Service, we don't have our "Main" method as we would otherwise use

In other words, when we have a simple console application we can:

[LoaderOptimization(LoaderOptimization.MultiDomainHost)] 
private static void Main(string[] args)
{
}

but for a Service, we implement the ServiceBase class and therefore don't have the main method, instead we have an

protected override void OnStart(string[] args)
{
}

But I am guessing that putting the attribute on that method won't have the same effect?

+1  A: 

You will still have a Main method for a Windows Service. It will typically be where you call ServiceBase.Run. The Visual Studio template for a Windows Service project will generate a class called Program that looks something like this and includes the Main() method:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            new Service1() 
        };
        ServiceBase.Run(ServicesToRun);
    }
}

You should be able to add an attribute to the Main() method there.

Quartermeister
Currently sitting here banging my head against the wall repeating the word "Doh"... Guess it is the heat that is getting to us here, we are no more than 3 who knew it but clearly forgotten it as well...But Thank you very much for the help >.<...
Jens