1

Is it possible to created a function in a web service to have multiple threads, one which returns a value to the user, and one that continues to process a transaction? I've never used any multithreading before and it seems like I would be able too by running the transaction Asynchronously. No code has been written yet. Trying to see if it is possible before I begin coding.

Csharp
  • 2,916
  • 16
  • 50
  • 77
Tim B
  • 193
  • 1
  • 7
  • 15
  • 4
    Normally, you would hand off long-running tasks to a Windows Service, or something similar. [This SO post](http://stackoverflow.com/q/13038823/102937) suggests using [NServiceBus](http://particular.net/). – Robert Harvey Jul 10 '13 at 19:37
  • What happens if the transaction processing fails? It would be too late to inform the client because you already responded. Generally, it's a bad idea to put long running processes within IIS anyway. – Paul Abbott Jul 10 '13 at 19:40
  • Do you mean a WCF service, or a legacy ASMX service? – John Saunders Jul 10 '13 at 19:47
  • Yes absolutely This was discussed in this question and answer; [http://stackoverflow.com/questions/1824933/right-way-to-create-thread-in-asp-net-web-application] – Oliver Gray Jul 10 '13 at 19:51
  • it seems you are trying to have a MOA instead of a web service –  Jul 10 '13 at 20:32

1 Answers1

1

Although you CAN fire off threads and the like, much like any other .NET application you have to take into account your operating environment.

Any long running process should really be handed off to another process like a Windows service as web server worker processes can and do get recycled and with it goes your threads. You're also tying up threads that could be used to further service requests to the web application.

In regards to what Paul Abbot said, in principle if you had a way of returning some kind of work ID to the client you could poll the status of the processing in another request, and this can apply within the same process or out of process in an external service.

Lloyd
  • 29,197
  • 4
  • 84
  • 98