0

This is something what im trying in MVC 2.0

public class SomeController : AsyncController
{  
    public void SampleAsync()
    {
        AsyncManager.OutstandingOperations.Increment();
        for(int i=0; i=100000; i++)
        {
        // Some Code... This loop is just for the testing.
        }
        AsyncManager.OutstandingOperations.Decrement();        
    }

    public ActionResult SampleCompleted(ActionResult result)
    {
        return result;
    }
}
  1. My question is what will be the parameter to SampleCompleted here it's ACTIONRESULT. I have tried to find out but every where i'll found something different. So what exactly it is ???
  2. Do i required to make changes in my Global.ascx file. like RouteCollection.MapRoute to RouteCollection.AsyncMapRoute
SynerCoder
  • 12,493
  • 4
  • 47
  • 78
Sham
  • 691
  • 2
  • 13
  • 26

1 Answers1

0
  1. The parameter or parameters of SampleCompleted will be variables which you specified in AsyncManager.Parameters - collection:

for example:

public void SampleAsync()
    {
        AsyncManager.OutstandingOperations.Increment();
        for(int i=0; i=100000; i++)
        {

        }
        AsyncManager.Parameters["myvariable"] = "variable value";
        AsyncManager.OutstandingOperations.Decrement();        
    }

    public ActionResult SampleCompleted(string myvariable)
    {
        //myvariable contains value "variable value"
        return result;
    }

2 . You not need to make changes.

testCoder
  • 7,155
  • 13
  • 56
  • 75
  • Thanks bro i think i found my answer. one more thing does it work asynchronously. Can i perform some other operation as well. – Sham Oct 30 '12 at 10:19
  • Yes you can perform other operations, but by default Controller class can perform async operations too, AsyncController - will be best choise for long running operations. – testCoder Oct 30 '12 at 10:40
  • If i'll click some other controller's action through my website, all async operation get's dismissed. how should i continue same, while surfing other pages ??? – Sham Oct 30 '12 at 10:45
  • If you call async action and if it long running request will be processed on server, and you get ability to call another controller actions asynchronously – testCoder Oct 30 '12 at 11:01
  • no my rest of the call is Synchronously then also it will work ?? – Sham Oct 30 '12 at 11:17
  • rest of call should be async, if they not the cause of it may be concurrent access to session thats why action blocking request, int that case you should decorate controller with attribute [SessionState(SessionStateBehavior.Disabled)] or ReadOnly to prevent concurrent access to session, here http://www.codeguru.com/csharp/.net/net_asp/mvc/working-with-asynchronous-operations-in-asp.net-mvc.htm very nice explanation of async operations in asp.net mvc – testCoder Oct 30 '12 at 11:28
  • the above solution is for mvc3.0, not for MVC2.0. Can u suggest me same thing in MVC2.0. – Sham Oct 30 '12 at 12:33
  • AsyncController is introduced in ASP.NET MVC 2 while SessionLess controller is introduced in ASP.NET MVC 3, but you can try to use as discussed from this http://weblogs.asp.net/imranbaloch/archive/2011/05/10/asynccontroller-v-s-sessionless-controller.aspx. – testCoder Oct 30 '12 at 12:52