c# - Correct way to get the CoreDispatcher in a Windows Store app -
i'm building windows store app, , have code needs posted ui thread.
for that, i'd retrieve coredispatcher , use post code.
it seems there few ways so:
// first way windows.applicationmodel.core.coreapplication.getcurrentview().corewindow.dispatcher; // second way window.current.dispatcher; i wonder 1 correct? or if both equivalent?
this preferred way:
windows.applicationmodel.core.coreapplication.mainview.corewindow.dispatcher.runasync(coredispatcherpriority.normal, () => { // ui update code goes here! }); the advantage has gets main coreapplicationview , available. more details here.
there 2 alternatives use.
first alternative
windows.applicationmodel.core.coreapplication.getcurrentview().corewindow.dispatcher this gets active view app, give null, if no views has been activated. more details here.
second alternative
window.current.dispatcher this solution not work when it's called thread returns null instead of ui dispatcher. more details here.
Comments
Post a Comment