简体   繁体   中英

Concerns about long running thread in WCF Windows Service

We're using a WCF Service and hosting it in our Windows Service. This concept is explained here .

We have a WCF service call that looks something like this:

    [System.ServiceModel.OperationContractAttribute(...)]
    [System.ServiceModel.FaultContractAttribute(...)]
    void TriggerLongRunningOperation(int id);

Within this WCF call, we spin off some fire-and-forget new threads to accomplish some background tasks. For the most part, there'll be only one, but there could be multiple. The WCF request basically finishes immediately, and the fire-and-forget thread performs its job.

        Task task = Task.Run(() =>
        {
            // some stuff.
        });

The operations that are spun off can last anywhere from 2 minutes to 1hr.

I'm concerned about having a long running thread in the WCF process, however, since it's not hosted via IIS, we don't have to worry about the app pool recycling.

What concerns should I be aware of, when running new threads in a WCF service hosted in a Windows service? What cases would the thread be aborted?

.NET 4.5.2

I would be concerned about reliability. Those threads can be aborted because an exception or system reboot, or many other situations on which the threads could be lost.

Also, I'd say that fire and forget approach has nothing to do with reliability: it just means that the caller doesn't care about the result of the whole operation.

Thus, I would look for some reliable message queueing like RabbitMQ . That is, you're going to process these fire and forget operations asynchronously in another thread from the one that fires those operations, and you'll be able to retry them if something goes wrong before they end up successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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