
Originally Posted by
eax
Ang technique ana is imong mga long running task(i.e. pag-stream from the webserver) is dili mahitabo sa main thread(GUI Thread).
maayong buntag
share ko usab ha...

kanang gigamit niya wala man na sa main thread, or what we call as UI Thread, Thread sa User Interface, or sa FORM. Thread na gigamit sa pag run sa FORM. (hope this is clear now).
ang DownloadStringAsync, nigamit na siya ug thread, pero ang mechanism niya ay dili visible sa programmer, automatic na sya nag spawn ug thread, automatic na sad siya mo balik sa UI thread. Unlike sa case na mo managed ka og ThreadPool.
pag command nimo sa DownloadStringAsync insde sa UI Thread, ni spawn sya ug another thread pero balik dayun sa UI Thread. kung imong tan-awon ang signature nya.... the statement is like this:
[HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading = true)]
public void DownloadStringAsync( Uri address, Object userToken)
ang not allowed na imong buhaton ay mo run ka ug external thread na mo modify sa resources sa UI nimo sa mga FORMS. ang UI Thread nimo siya ra dapat mo modify ana. ReadOnly ra sya dapat. naay mga records ang UI thread nimo sa imong mga FORMS, kung imong e modify imong forms from other Thread, maboang imong UI Thread unsay nahitabo, sa iyang gibantayan na resources. mau na mo kaging, kay e lock niya unya mag rebuild siya sya iyang resource...
karon unsa pag identify kung naa ka ba sa UI thread or sa lain na thread para mag makagamit ka og method Invokes like.
BeginInvoke = Executes the specified delegate asynchronously on the thread that the control's underlying handle was created on.
daghan paagi ana para ma avoid nimo na... like gamit ka ug InvokeRequired,
example:
if(InvokeRequired){
outside ni sa thread.
}
else{
naa ka diri sa ui thread
}
hope this help.