tags:

views:

85

answers:

1

Hi guys

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. Maybe we have to do something else to start the thread.

The line of code we only have to type is MonitorThread.Start;

Where and how we can to start the thread??

Thanks.

+2  A: 

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).

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.

Rob Kennedy