8

In WCF you have something like this

[ServiceContract]
public interface IDoAuditService
{
    [OperationContract(IsOneWay = true)]
    [WebInvoke]
    void Audit(AuditEntry auditEntry);
}

Which as a result will allow the consumers to issue a request and continuing the flow without waiting for a response.

I've tried Asp.net MVC with AsyncController but the consumer will still block and wait until the callback will be called in the controller.

What I want is to use Asp.Net MVC but the behavior WCF like, I want to issue a request and continue the flow without waiting the request to be processed

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ruslander
  • 3,815
  • 4
  • 32
  • 34

1 Answers1

3

What about performing the action body async on the server and just returning to the caller immediately. It's not exactly a fire and forget but it will emulate that.

public ActionResult MyAction()
{
    var workingThread = new Thread(OperationToCallAsync);
    workingThread.Start();

    return View();
}

void OperationToCallAsync()
{
    ...
}
Dan Carlstedt
  • 311
  • 2
  • 9
  • Probably this can be a solution, I was assuming that what I want is common scenario and is implemented natively but I don't know about. – ruslander Jun 20 '12 at 14:55
  • I am not aware of this supported natively. – Dan Carlstedt Jun 20 '12 at 15:30
  • This is what I thought also but what happens to workingThread when MyAction() goes out of scope? – dalcantara Jun 29 '12 at 15:34
  • In the example workingThread is a foreground thread so this thread will complete as you would expect. However if this was a background thread and all of the remaining foreground threads in the process have completed then this thread would stop executing b/c the process would exit. However in a web application the hosting process wouldn't exit until it's recycled or forcibly terminated. – Dan Carlstedt Jun 29 '12 at 18:25