El siguiente es mi código de servicio de Windows. Cuando estoy depurando el código, obtengo el error / excepción:
El inicializador de tipo para 'CSMessageUtility.CSDetails' arrojó una excepción.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using CSMessageUtility;
namespace CS_Data_Trasmmiting_Service
{
public partial class svcCSWinServ : ServiceBase
{
//private string sLogFormat;
//private string sErrorTime;
private Thread new_thread;
Logger logObject = new Logger();
private bool isenable = true;
public svcCSWinServ()
{
InitializeComponent();
logObject.append("Initialize Service " + DateTime.Now.ToString(), 70);
CheckForAlarms();
}
protected override void OnStart(string[] args)
{
try
{
new_thread = new Thread(new ThreadStart(CheckForAlarms));
new_thread.Start();
}
catch
{
}
logObject.append("Service Started successfully " + DateTime.Now.ToString(), 70);
}
protected override void OnStop()
{
try
{
isenable = false;
new_thread.Abort();
}
catch
{
}
logObject.append("Service Stopped successfully " + DateTime.Now.ToString(), 70);
}
void CheckForAlarms()
{
try
{
while (true)
{
//if((DateTime.Now.ToString("HH:mm") == "18:00"))
//{
logObject.append("Start Sending Data " +DateTime.Now.ToString(), 70);
try
{
//SendAllInfo();
string str = CSMessageUtility.CSDetails.createDHSMessageFormat();
Thread.Sleep(2000);
string str1 = CSMessageUtility.CSDetails.createEALMessageFormat();
Thread.Sleep(2000);
string str2 = CSMessageUtility.CSDetails.createProductStatusMessageForamt();
Thread.Sleep(2000);
string str3 = CSMessageUtility.CSDetails.createEODMessageFormat();
Thread.Sleep(2000);
string str4 = CSDetails.createProductReceiptEntryatBOSMessageFormat();
Thread.Sleep(2000);
string str5 = CSMessageUtility.CSDetails.createProductSaleMessageFormat();
Thread.Sleep(2000);
string str6 = CSMessageUtility.CSDetails.createTotalizerExceptionMessageFormat();
Thread.Sleep(2000);
//CSMessageUtility.CSDetails.createDailyCOtransferMessageFormat();
//Thread.Sleep(2000);
}
catch (Exception ee)
{
logObject.append(ee.Message, 70);
}
logObject.append("Finished Sending Data " +DateTime.Now.ToString(), 70);
Thread.Sleep(3000);
//}
//Thread.Sleep(20000);
}
}
catch (Exception ex)
{
logObject.append("Thread Exception: "+ ex.Message + " "+ DateTime.Now.ToString(), 70);
try
{
new_thread.Abort();
}
catch (Exception ex1)
{
logObject.append("Thread Exception: " +ex1.Message + " " + DateTime.Now.ToString(), 70);
}
if (isenable == true)
{
new_thread = new Thread(new ThreadStart(CheckForAlarms));
new_thread.Start();
}
}
}
}
}