c# - How to process time consuming serverside initialization in MVC? -
c# - How to process time consuming serverside initialization in MVC? -
i started little project, expieriencing world of js , html5.
i tried few months ago, already, stopped, because i've had not plenty time create mvc single page application scratch. there many concepts , patterns, had understood , have regretted losing knowledge lack of utilize on daily work. use or lose it!
yesterday found this post on john papa's blog , thought great utilize start. it's mvc template, called hottowel, implements great concepts data-binding, minification , forth. experience code far needed moment , experience further, i'd need to.
i'd build application fetching info works existing info model project. in our silverlight application, bootstrap through preloading , initializing dictionaries , other properties , calling async init()
methods (e.g. downloading xml files containing custom codes , set them dictionaries). mef used rid of unhandy dependencies.
as far understood server side initialization has done in application_start()
method in global.asax file. wonder how i'd await async calls in method? what's best practices? queries on client side heavily rely on these classes initialized. options there?
my thoughts following:
application_start()
fires , forgets async initialization process. if i'd perform request (on controller guess) before initialization finished, i'd have wait callback of initialization process , start queries arrives. advantage of this'd be, initialization runs, while user can navigate through application. i'd implement kind of lazy initialization. i'd process initialization first request made. may take long first request, though. i'd run initialization process synchronously in application_start()
. major disadvantage of i've seen far is, browser window seems freezed user. i'd comfortable solution, if possible allow user maintain track of current initialization status (some kind of splash screen). though don't know how of them work concretly , glad if of give me advices how , start.
you can utilize task<mydatamodel>
represent data.
static task<mydatamodel> datatask; public static task<mydatamodel> loaddatamodelasync() { var ret = new mydatamodel(); await ret.init(); homecoming ret; }
kick off in application_start
(or static constructor):
datatask = loaddatamodelasync();
then each of actions needs can await
complete:
mydatamodel info = await datatask; ...
if it's complete, await
observe , go on (synchronously).
c# asp.net-mvc server-side single-page-application hottowel
Comments
Post a Comment