简体   繁体   English

如何在Windows XP delphi 7中启动进入服务的线程?

[英]How to start a thread into a service in delphi 7, Windows XP?

We need to Start a thread into a service application we developed. 我们需要启动一个线程进入我们开发的服务应用程序。

We did in the OnExecute event, and it failed, and later we did in the OnStart event, and it failed again. 我们在OnExecute事件中发生了,但是失败了,后来在OnStart事件中发生了,并且再次失败了。 Maybe we have to do something else to start the thread. 也许我们必须做些其他的事情来启动线程。

The line of code we only have to type is MonitorThread.Start; 我们只需键入的代码行是MonitorThread.Start;。

Where and how we can to start the thread?? 我们在哪里以及如何启动线程?

Thanks. 谢谢。

On the face of it, starting a thread in a service is no different from starting a thread in any other kind of application. 从表面上看,在服务中启动线程与在任何其他类型的应用程序中启动线程没有什么不同。 Simply instantiate the thread object and let it run. 只需实例化线程对象并使其运行。 If you created the object in a suspended state, then call Start on it (or, in versions earlier than 2010, Resume ). 如果您在挂起状态下创建了对象,请对其调用Start (或者在2010年之前的版本中 ,调用Resume )。

MonitorThread := TMonitorThread.Create;
MonitorThread.Start; // or MonitorThread.Resume

If that doesn't work, then you need to take a closer look at exactly what doesn't work. 如果那行不通,那么您需要仔细看一下到底什么行不通。 Examine exception messages and return codes. 检查异常消息和返回码。 Use the debugger to narrow things down. 使用调试器缩小范围。

If it's possible, I advise you to not create the thread suspended. 如果可能,我建议您不要创建挂起的线程。 Instead, just provide the object all the parameters it needs in its constructor. 相反,只需在对象的构造函数中为其提供所需的所有参数即可。 Let it initialize itself, and it will start running just before the constructor returns to the caller. 让它初始化自己,它将在构造函数返回给调用者之前开始运行。 No need for additional thread management outside the thread object. 不需要在线程对象之外进行其他线程管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM