我已經創建了一個windows服務併爲其創建了安裝程序。它已安裝並啓動,但我寫入其中的代碼未執行。實際上,當我從服務窗口啓動服務時,OnStart()函數未被觸發。也沒有初始化組件(),也沒有靜態無效的主要功能..任何一個可以幫助我吧安裝了windows服務但不工作
請指導我在哪裏做錯了。
這裏有一些代碼行。讓我知道如果u想要更多的東西我已經寫
public partial class iMArchiveService : ServiceBase
{
Boolean isArchiving = false;
public iMArchiveService()
{
MyException.CreateLog("iMArchiveService: Inside Constructor. Initializing Component");
InitializeComponent();
MyException.CreateLog("iMArchiveService: Component Initialized. Timer is set as: " + TimeMachine.Interval.ToString() + " milliseconds");
}
protected void TimeMachine_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
MyException.CreateLog("iMArchiveService: Inside Tick Try. Value of isArchiving variable before condition is: " + isArchiving.ToString());
if (!isArchiving)
isArchiving = new iM.OrderArchiving.ArchiveOrderXML().ArchiveOrderService();
MyException.CreateLog("iMArchiveService: Inside Tick Try. Value of isArchiving variable after condition is: " + isArchiving.ToString());
}
catch (Exception ex)
{
MyException.CreateLog("iMArchiveService: Inside Tick Catch :(");
}
}
protected override void OnStart(string[] args)
{
TimeMachine.Enabled = true;
MyException.CreateLog("iMArchiveService Started: " + DateTime.Now.ToString());
}
protected override void OnStop()
{
TimeMachine.Enabled = false;
MyException.CreateLog("iMArchiveService Stopped: " + DateTime.Now.ToString());
}
}
上面的代碼是服務file.cs
這裏是我的項目安裝文件
namespace iM.OrderArchivingService
{
[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
}
}
這裏是InitializeComponenet功能 -
private void InitializeComponent()
{
this.myServiceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
this.myServiceInstaller = new System.ServiceProcess.ServiceInstaller();
//
// myServiceProcessInstaller
//
this.myServiceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.myServiceProcessInstaller.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.myServiceInstaller});
this.myServiceProcessInstaller.Password = null;
this.myServiceProcessInstaller.Username = null;
//
// myServiceInstaller
//
this.myServiceInstaller.ServiceName = "iMArchiveService";
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.myServiceProcessInstaller});
}
這裏是program.cs文件
namespace iM.OrderArchivingService
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new iMArchiveService() };
ServiceBase.Run(ServicesToRun);
}
}
}
因爲你看我已經寫了代碼登錄時初始化或開始..但沒有日誌正在作出。
編輯:
代碼定時器(時間機器)
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.TimeMachine = new System.Timers.Timer(3600000);
//
// TimeMachine
//
this.TimeMachine.Interval = 3600000;
this.TimeMachine.Elapsed += new System.Timers.ElapsedEventHandler(TimeMachine_Elapsed);
//
// iMArchiveService
//
this.ServiceName = "iMArchiveService";
}
日Thnx
TimeMachine計時器的間隔是多少? – Coder 2012-04-20 06:23:46
添加了計時器代碼..但至少它應該寫入我開始編碼的日誌。該日誌也不寫爲 – 1Mayur 2012-04-20 07:05:48
我猜它不是計時器問題...日誌記錄進一步顯示它到達projectinstaller初始化組件函數,但它沒有得到什麼必須開始。我的意思是我的初始化函數需要引用我的服務基類... – 1Mayur 2012-04-20 09:35:56