views:

95

answers:

3

I have got few questions regarding creating windows service. I have created a windows service.But Im getting an error reagrding that. public partial class xyz : servicebase { public xyz() { InitializeCompoenent(); } }

it couldn't resolve InitializeComponent().Does anybody any reason. I have set it up out as console application instead of windows application.

+2  A: 

You used the console application template? That's not right you would have to do allot of manual work like creating the InitializeComponent() method. The best solution is to create a new project using the Windows Service application template. For complete instructions see http://msdn.microsoft.com/en-us/library/zt39148a.aspx

olle
Yea, if you already written lots of codes, it's stil not that tedious to recreate a new Windows Service project and copy the codes into the right place.
o.k.w
@okw: Codes? Why copy/paste when you can move the code into a project that is just by both the console application and by the windows service?
yodaj007
Yeah creating a windows service from scratch solved the above issue.
alice7
A: 

On your project select Add->New item->Windows Service. Give a name to your service.

Now, imports the necessary code you were using from your console file (I'm guessing from the lack of information) to the service file.

So, now you will have a valid window service component in your project. You can remove the old console file.

Don't forget to modify the code in the main in Program.cs:

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

If you want to run from the command-line for debugging purposes then check this out this answer.

MattH