【发布时间】:2011-12-11 16:00:46
【问题描述】:
我在安装我的服务应用程序时遇到问题。当我运行我的调试模式时,它一切正常,所有逻辑的东西都正常工作。我以前写过服务应用程序,比较两者,这个和一个工作的应用程序之间几乎没有区别。提前感谢您对我的代码的任何帮助:
class MainClass : ServiceBase
{
ABCSQLCon _SQLCon = new ABCSQLCon();
private int cycleTime = 0;
private delegate void processError(String errorMessage);
static void Main(string[] args)
{
#if(!DEBUG)
ServiceBase.Run(new MainClass());
#else
MainClass service = new MainClass();
service.OnStart(new string[0]);
#endif
}
protected override void OnStart(string[] args)
{
addToLog("Testing SQL Connection...", "Log");
cycleTime = _SQLCon.sleepTime;
addToLog("Sleep Time has been set...", "Log");
if (_SQLCon.testSQLConnection())
{
addToLog("Connection to SQL Database succeeded", "Log");
// queryThread();
//not neccessary to make applicated multithreaded yet.
addToLog("Starting Query Thread...", "Log");
ThreadStart queryCycle = new ThreadStart(queryThread);
Thread qThread = new Thread(queryCycle);
qThread.Start();
}
}
private void startProgram()
{
}
protected override void OnStop()
{
base.OnStop();
}
public MainClass()
{
this.ServiceName = "ABCSQL Engine";
}
啊,我现在发现了问题,sql 连接测试只是一个快速打开和关闭的工作,但我没有看到或意识到我在哪里初始化那个 _SQLCON 对象。 我已将其移至我的方法中,并且现在可以正常工作。快乐的日子,感谢您的回答,因为它帮助我找到了我没有找到的地方。 x
【问题讨论】:
-
请澄清问题所在 - 您的问题不清楚。
-
testSQLConnection() 可能需要很长时间才能完成。服务控制管理器只给你很短的时间来完成
OnStart方法,然后它就会推断它已挂起。