1

When I call serviceHost.Close(), even if I put a timeout value serviceHost.Close(TimeSpan.FromMinutes(10)), while it stops receiving messages, it seems one or two of my messages gets lost from time to time.

I want my service to stop in the middle of an operation, but process the rest of the messages already received. Is there a way to gracefully close the service while a message is still processing?

I already set the closeTimeout and receiveTimeout in the app.config to 10 minutes, also use RequestAdditionalTime(600000) but I still get this issue. It does not close in 10 minutes, rather 1 minute at max.

Binding I am using is netMsmqBinding.

EDIT:

I temporarily fixed the problem by adding a while statement in the ServiceBase method OnStop that if the process is not finish then it will keep looping. It seems like a dirty hack, but it works for now. Let me know if there's a cleaner way to end it gracefully.

tshepang
  • 12,111
  • 21
  • 91
  • 136
MilkTea027
  • 301
  • 1
  • 5
  • 24

0 Answers0