vb.net - Update control asynchronously -
i've been reading on net how solve problem of updating controls different threads 1 contains command , read "pro vb 2010 , .net 4.0 platform" , start wonder. next code performing in synchronous fashion?
private sub savedata(byval filepath string) if invokerequired me.invoke(new methodinvoker(addressof savedata)) else ... actual code end if end sub
it depends on calling context.
if calling ui thread or main thread, yes function synchronously.
if phone call thread not ui or main thread, going function asynchronously ui or main thread, synchronously calling thread, waiting until ui or main thread done processing delegate.
so can go both ways. can operate synchronously , asynchronously. think missing code not preform in synchronous or asynchronous fashion, execution of code either synchronous or asynchronous.
the reason why create update function:
private sub updatelabel(byval tlabel label, byval value string) if tlabel.invokerequired me.invoke(new methodinvoker(addressof updatelabel) else tlabel.text = value end if end sub
is can phone call whenever want alter text, without having worry cross thread exception.
this method safe phone call ui thread during click event , safe phone call along running background thread, because alter still ever made on ui or main thread. utilize code ensure synchronicity changes controls owned other threads.
this style of updating meant synchronize changes , avoid cross threading.
vb.net asynchronous synchronous multithreading
No comments:
Post a Comment