c# - CoreDispatcher.HasThreadAccess "breaking change" -
i taking on application developed mvvmcross.vnext.
while trying update mvvmcross.v3, found following breaking change: in constructor of mainviewmodel, show loginviewmodel (showviewmodel()). worked fine in vnext.
v3, loginview doesn't show.
after long search, found out following code, added in mvxstoremainthreaddispatcher.requestmainthreadaction :
if (_uidispatcher.hasthreadaccess) { action(); return true; } was responsible troubles.
if comment out, application works previously, guess code there reasons...
have suggestions ?
can force previous behavior without changing mvvmcross source code?
should refactor code handle loginview differently ?
in advance comments.
philippe
while trying update mvvmcross.v3, found following breaking change: in constructor of mainviewmodel, show loginviewmodel (showviewmodel()). worked fine in vnext.
i think constructor navigation have broken on several platforms in mvvmcross version. honest, think lucky worked before.
the problem viewmodels constructed (or located) during view events such viewdidload, onnavigatedto, , oncreate - , these events called during 'page transitions'
to work around need move login navigation out of constructor.
how depends on app
if need home->login backstack, can trigger off async or time delay or can trigger off other view event such
viewdidappearif don't need backstack way implement sort of thing use custom
imvxappstart- like:public class appstart : mvxnavigatingobject , imvxappstart { public void start(object hint = null) { var authservice = mvx.resolve<imyserice>(); if (authservice.isloggedin) { showviewmodel<homeviewmodel>(); } else { showviewmodel<loginviewmodel>(); } } }(you can see example in https://github.com/slodge/mvvmcross/blob/v3/sample%20-%20cirriousconference/cirrious.conference.core/applicationobjects/appstart.cs)
this can registered in app.cs startup using:
registerappstart(new appstart());
Comments
Post a Comment