yes, I know about the stopwatch, but how do I implement it to get the time interval value when the Submit button is pressed and when the data is fully loaded?
even if we have get the value, so what? we would not know where the problem occurs. I just want to know why one can load its data almost instantly, while the others it takes more than 20 seconds to load the same set of data, when it gets its input from HTML
textboxes. Those 2 sets of codes are equivalent.
public static List<PPL_PRODUCT_TESTID2> ListTestID2()
{
using (TESTID2Entities context = new TESTID2Entities())
{
var query =
from products in context.PPL_PRODUCT_TESTID2
where products.MONO == 5656303 && products.MAINSERNO == "40000020159391" // not to be hardcoded.
select products;
return query.ToList();
}
}
public static List<PPL_PRODUCT_TESTID2> SelectTestID2(Int64 MONO, string MAINSERNO)
{
using (TESTID2Entities context = new TESTID2Entities())
{
var query =
from products in context.PPL_PRODUCT_TESTID2
where products.MONO == MONO && products.MAINSERNO == MAINSERNO
select products;
return query.ToList();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using Mvc4_TESTID2.Controllers;
namespace Mvc4_TESTID2
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new RequestTimingFilter());
}
}
}
so what is next? yes, those data can be loaded as usual, but takes unusual time to load.. even the initial webpage takes some time to come out.
ignatandrei
All-Star
135148 Points
21679 Posts
Moderator
MVP
Re: Am I doing the correct thing for MVC?
Feb 24, 2013 06:56 AM|LINK
http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx
Put into ViewBag or Session.
kelvin tan
Member
50 Points
95 Posts
Re: Am I doing the correct thing for MVC?
Feb 25, 2013 04:03 AM|LINK
yes, I know about the stopwatch, but how do I implement it to get the time interval value when the Submit button is pressed and when the data is fully loaded?
even if we have get the value, so what? we would not know where the problem occurs. I just want to know why one can load its data almost instantly, while the others it takes more than 20 seconds to load the same set of data, when it gets its input from HTML textboxes. Those 2 sets of codes are equivalent.
public static List<PPL_PRODUCT_TESTID2> ListTestID2() { using (TESTID2Entities context = new TESTID2Entities()) { var query = from products in context.PPL_PRODUCT_TESTID2 where products.MONO == 5656303 && products.MAINSERNO == "40000020159391" // not to be hardcoded. select products; return query.ToList(); } } public static List<PPL_PRODUCT_TESTID2> SelectTestID2(Int64 MONO, string MAINSERNO) { using (TESTID2Entities context = new TESTID2Entities()) { var query = from products in context.PPL_PRODUCT_TESTID2 where products.MONO == MONO && products.MAINSERNO == MAINSERNO select products; return query.ToList(); } }what could go wrong?
ignatandrei
All-Star
135148 Points
21679 Posts
Moderator
MVP
Re: Am I doing the correct thing for MVC?
Feb 25, 2013 04:09 AM|LINK
Put this filter to work and tell the results
http://bradwilson.typepad.com/blog/2010/07/aspnet-mvc-filters-and-statefulness.html
kelvin tan
Member
50 Points
95 Posts
Re: Am I doing the correct thing for MVC?
Feb 25, 2013 07:35 AM|LINK
I look into the above link, does not really understand what is about :(
any other simpler solutions to see where /why the delays occurs?
ignatandrei
All-Star
135148 Points
21679 Posts
Moderator
MVP
Re: Am I doing the correct thing for MVC?
Feb 25, 2013 07:37 AM|LINK
just copy the example ;-)
kelvin tan
Member
50 Points
95 Posts
Re: Am I doing the correct thing for MVC?
Feb 25, 2013 11:11 PM|LINK
I have put the above link code into the controller as such:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Mvc4_TESTID2.Models; using System.Diagnostics; namespace Mvc4_TESTID2.Controllers { public class TestID2Controller : Controller { // // GET: /TestID2/ public ActionResult Index() { return View(); } public ActionResult ListTestID2() { return View(TestID2.ListTestID2()); } public ViewResult SelectTestID2() { Int64 MoNo = Convert.ToInt64(Request.Form["MoNo"]); string MainSerNo = Request.Form["MainSerNo"]; return View(TestID2.SelectTestID2(MoNo, MainSerNo)); } } public class RequestTimingFilter : IActionFilter, IResultFilter { Stopwatch GetTimer(ControllerContext context, string name) { string key = "__timer__" + name; if (context.HttpContext.Items.Contains(key)) { return (Stopwatch)context.HttpContext.Items[key]; } var result = new Stopwatch(); context.HttpContext.Items[key] = result; return result; } public void OnActionExecuting(ActionExecutingContext filterContext) { GetTimer(filterContext, "action").Start(); } public void OnActionExecuted(ActionExecutedContext filterContext) { GetTimer(filterContext, "action").Stop(); } public void OnResultExecuting(ResultExecutingContext filterContext) { GetTimer(filterContext, "render").Start(); } public void OnResultExecuted(ResultExecutedContext filterContext) { var renderTimer = GetTimer(filterContext, "render"); renderTimer.Stop(); var actionTimer = GetTimer(filterContext, "action"); var response = filterContext.HttpContext.Response; if (response.ContentType == "text/html") { response.Write( String.Format( "<p>Action '{0} :: {1}', Execute: {2}ms, Render: {3}ms.</p>", filterContext.RouteData.Values["controller"], filterContext.RouteData.Values["action"], actionTimer.ElapsedMilliseconds, renderTimer.ElapsedMilliseconds ) ); } } } }how do I view those timing values? even if those timing values, how are we able to trace where the problem lies?
ignatandrei
All-Star
135148 Points
21679 Posts
Moderator
MVP
Re: Am I doing the correct thing for MVC?
Feb 26, 2013 01:40 AM|LINK
and add to global.asax, into the filters.
kelvin tan
Member
50 Points
95 Posts
Re: Am I doing the correct thing for MVC?
Feb 26, 2013 01:45 AM|LINK
pardon me for being a MVC idiot...:(
what code to add to global.asax? I suppose I need to view those timing values, how do I do that?
actually I am still not sure how this can help to solve my issue :(
ignatandrei
All-Star
135148 Points
21679 Posts
Moderator
MVP
Re: Am I doing the correct thing for MVC?
Feb 26, 2013 02:13 AM|LINK
kelvin tan
Member
50 Points
95 Posts
Re: Am I doing the correct thing for MVC?
Feb 26, 2013 02:31 AM|LINK
ok, with what you have suggested:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Mvc; using System.Web.Routing; using Mvc4_TESTID2.Controllers; namespace Mvc4_TESTID2 { // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=9394801 public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); } public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new RequestTimingFilter()); } } }so what is next? yes, those data can be loaded as usual, but takes unusual time to load.. even the initial webpage takes some time to come out.