0

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();
}
Nuthan Gowda
  • 255
  • 3
  • 6
  • 19
  • Have you first verified the service whether it's *started* ? – Kurubaran Nov 14 '14 at 09:29
  • Yes, After installing I started the service and I have a logFile, There also I find service started successfully but after this nothing will be executed. – Nuthan Gowda Nov 14 '14 at 09:33
  • Seems you will have to debug the hard way. Place all the code in Try Catch block. Write event log after every statement. Probably this will give you some clue. Also check if there are any issues with email setup. Any Admin privilege issues? – NP3 Nov 14 '14 at 09:36
  • Do you have logging within your code ? is *Timer.Elapsed* firing for every 5min ? – Kurubaran Nov 14 '14 at 09:41
  • Yes, I have logging. This event is not firing in Windows Server 2012 but It will work fine in Windows 7 – Nuthan Gowda Nov 14 '14 at 09:46
  • @NuthanGowda Check the *Event Viewer* to confirm if there are any unhandled exceptions. – Kurubaran Nov 14 '14 at 10:19
  • I have already cross checked the event viewer, There is nothing, Only 1 thing was there which shows Windows service installed successfully. – Nuthan Gowda Nov 14 '14 at 10:24
  • Will this might be causing any issue ? http://stackoverflow.com/questions/14684541/why-doesnt-windows-server-2012-support-net-framework-4-0 – Nuthan Gowda Nov 14 '14 at 10:25
  • It shouldn't if you've built your application against 4 or 4.5. What version of the framework have you built your application against? Though I can't see how this would make a difference as your application wouldn't even run if the server didn't have the appropriate framework. You need to get the try catch around all of your code in OnStart (as suggested by NP3) and log any exceptions using your WriteToLogFile method. – Nattrass Nov 15 '14 at 11:28

3 Answers3

0

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.

Nuthan Gowda
  • 255
  • 3
  • 6
  • 19
0

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.

0

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 .

PRathore
  • 93
  • 1
  • 4