简体   繁体   中英

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();
}

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.

Apart of target platform there is also target framework important. If you have application targeted on version 3.5 make sure there is .Net Framework 3.5 feature enabled on the server. Otherwise you may run into hard to recognize errors loop while trying to install and start a system service.

In my case I have to delete the old windows service using command prompt in admin mode using:

SC DELETE <service name>

then rebuild the application as mentioned by > >Nuthan Gowda and it worked .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM