Search code examples
c#windows-serviceswindows-server-2012

Windows service installing in Windows server 2012


I'm facing a strange problem after installing the Windows service.

This Windows service will call a method to send mail every 5 minutes.

I have developed the windows service using C# visual Studio 2010.

After the development I have taken the release build version and Installed in my system (that is windows 7 OS) and it works without any problem.

Once the same thing is done in the Windows server 2012 then the service will be installed but the nothing happens there after.

I have used System.Threading.Timer at present. Even I tried using System.Timers.Timer. Both of these will work in my system but wont work in the Server.

I can post the code if required.

private Timer IntervalTimer;
protected override void OnStart(string[] args)
{
        Server.WriteToLogFile("Windows Service started");
        int loopTime = 5; //Every 5 Minutes
        Server.WriteToLogFile("Loop Time : " + loopTime.ToString());

        TimeSpan tsInterval = new TimeSpan(0, loopTime, 0);
        IntervalTimer = new Timer(new TimerCallback(IntervalTimer_Elapsed), null, tsInterval, tsInterval);
 }
private void IntervalTimer_Elapsed(object state)
{
     Server.WriteToLogFile("Event Fired");
     Library library = new Library();
     library.Start();
}

Solution

  • In the Project properties - > Build Tab - > Platform Target was - x86. So it was giving me error in the windows server 2012 which is of 64bit OS. Now I changed it to anycpu and it worked fine.

    Thanks for your suggestions.