Windows服务启动,但OnStart()后立即停止而没有错误

时间:2011-10-28 12:36:21

标签: c# windows-services 32bit-64bit remote-desktop

我最近将TCP端口侦听应用程序转换为Windows服务,在我的32位Vista笔记本电脑上安装并运行完美。 问题是,安装完成后,我试图在64位Win7上运行服务(通过Remote Dekstop),它整齐地递给我一个错误1053,基本上说明服务在启动时超时。

现在我已经让它启动而没有错误,但它只是立即退出而没有任何错误或任何eventLogging过去的OnStart。 我已经尝试用线程替换我的Timer,看看这可能是奇怪的开始的问题,但没有运气......这是服务的OnStart方法和意味着连续运行的方法。

protected override void OnStart(string[] args)
    {
        myServer.Start();
        eventLog1.WriteEntry("Server started.");               
        mWorker = new Thread(StartUp);
        eventLog1.WriteEntry("Starting up CykelScore service.");
        mWorker.Start();//Start the service
        //timer.Start();              // Start the timer
    }

    private void StartUp(object arg)
    {
        while (true)
        {
            eventLog1.WriteEntry("Running.");
            if (mStop.WaitOne(10000)) return;
            {
                if (Monitor.dataCount > 0)
                {
                    string tmp = "";
                    eventLog1.WriteEntry("Antal tags: " + Monitor.dataCount.ToString());
                    lockedUp.WaitOne();
                    try
                    {
                        tmp = Monitor.PopData();
                    }
                    catch (Exception ex)
                    {
                        eventLog1.WriteEntry("Fejl:" + ex.ToString());
                    }
                    eventLog1.WriteEntry("Recieved: " + tmp);
                    string buffer = tmp;
                    string antenna = (buffer.Split(',')[0]).Replace(" ", "");
                    string time = buffer.Split(',')[2];
                    string RFIDNR = (buffer.Split(',')[1]).Replace(" ", "");

                    string[] ART = new string[3];
                    ART[0] = antenna;
                    ART[1] = RFIDNR;
                    ART[2] = time;

                    if (lastreceivedtagID == RFIDNR)
                    {
                        eventLog1.WriteEntry("Same tag as last time. No need to check database");
                    }
                    else
                    {
                        if (!DataHandler.LoggedInCurrentTimespan(ART))
                        {
                            try
                            {
                                DataHandler.SaveToLocal(ART);
                                eventLog1.WriteEntry("Data saved to local database");

                                DataHandler.SendToRemote(tmp, Monitor.server, Monitor.database, Monitor.username, Monitor.password);
                                eventLog1.WriteEntry("Data sent to remote database");
                            }
                            catch (Exception ex)
                            {
                                eventLog1.WriteEntry("Fejl" + ex.ToString());
                            }
                        }
                        else
                            eventLog1.WriteEntry("Discarding data. Already in local database");
                    }
                    lastreceivedtagID = RFIDNR;
                    lockedUp.ReleaseMutex();
                }
            }
        }
    }

有没有人知道可能是什么问题?

0 个答案:

没有答案
相关问题