开发者

Specify LoaderOptimization's for Windows Services

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 a开发者_StackOverflow社区ttribute on that method won't have the same effect?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜