Skip to content

Instantly share code, notes, and snippets.

@darrenshrwd
Last active August 29, 2015 14:05
Show Gist options
  • Save darrenshrwd/8bf3f7f874bceadcb4b0 to your computer and use it in GitHub Desktop.
Save darrenshrwd/8bf3f7f874bceadcb4b0 to your computer and use it in GitHub Desktop.
Faster controller
private class SomeModelDemoOnly
{
public string Text { get; set; }
}
// Traditional way
public ActionResult Index()
{
Thread.Sleep(5000); // Do lots of DB and network stuff
var m = new SomeModelDemoOnly()
{
Text = "Hello"
};
return View(m);
}
// Faster way
public ActionResult FasterIndex()
{
var asyncModel = new AsyncModel<SomeModelDemoOnly>(delegate
{
Thread.Sleep(5000); // Do lots of DB and network stuff
var m = new SomeModelDemoOnly {Text = "Hello"};
return m;
});
return View(asyncModel);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment