1

Here is my scenario.

I want to create a web endpoint that will kick off a service that may be long-running, perhaps 20-30 minutes. I'd like to return an HttpResponseResult immediately and trigger the service to run asynchronously, instead of having to wait for the service to complete before returning a response to client.

What is the easiest way to go about doing this? I don't need to return any sort of result from the service, just trigger it.

1

2 Answers 2

1

Just run a task using Task.Run(() => <trigger service call> ) and ignore the return value. The only down side of this is that it will consume a thread from the thread pool. If the service has an asynchronous version of the operation you are calling you can use a TaskCompletionSource

Sign up to request clarification or add additional context in comments.

Comments

0

SignalR will be my choice to do this kind of behavior. Tutorial is here.

Basically, a client invokes a server method/action and is 'done' (you can continue and do whatever y you want in the client side). Once the server is done it pushes data/notification to client via RPC.

On the server side you can execute the code anyway you like, synchronously or async.

1 Comment

Wouldn't there be an easier way by just created an async method that I can call. The part I am confused about is how to implement an async method when I am completely unconcerned with the result from the aysnc process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.