Page 5 of 6 FirstFirst ... 23456 LastLast
Results 41 to 50 of 54
  1. #41
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1

    Quote Originally Posted by eax View Post
    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.

  2. #42
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by junkfactory View Post
    Instead nga mag paabot ang script sa result sa "GetContents", ako nalang gi pa register ang scripts ug function nga tawagon sa app once mahuman na ang download process. Di unta ko ganahan ingon ani pero saon mao ra man solution ako nakit-an sa pagka-karon.
    sakto ka bai na naay sayop... hehehehe

    Quote Originally Posted by junkfactory View Post
    Yep. Mao nga ang title sa thread is "... executed in another thread?" Pero sa muna-munang paningkamot nga dili kaayo ma complicated ang app, ni adto nalang ko sa event based solution para ma solbad na ni.
    I hope na wala ka nag refer sa DownloadStringAsync, kay dili man na siya event based solution. Thread na siya bai, internally. pero gi term lng na na Async sa microsoft kay ni run siya parallel sa UI thread nimo. nag ADD lang ka ug Delegate sa iyang Event Propery na DownloadProgressChangedEventHandler ug DownloadStringCompletedEventHandler, ang Delegate nimo naa sa solod sa imong UI Thread... kining mga eventhandler kuyog ni sa thread na atong panganlang nalang ug "DownloadStringAsync" kini si DownloadStringAsync, nag raise ug event, pero dili nimo makuha ang event or mahibaw-an kung wala kay delegate. kanang mga delegate nimo, sila maoy ni represent sa outside thread. murag company ba. naa kay engineer na edelegate nimo sa event meeting sa thailand, singapore, hongkong etc...para mahibaw-an nimo ang result sa mga events, mo paagi ka ni delegate.

    Quote Originally Posted by junkfactory View Post
    register ang scripts ug function nga tawagon sa app once mahuman na ang download process.
    sakto imong gibuhat na mo gamit ka ug webclient, although daghan way... like what I mentioned sa taas. para mahibaw-an nimo na nahuman na ang download, mag assign ka ug delegate. kay "DownloadStringAsync" mag download og resources, pero mangayo ra sya ug delegate diha nimo. pero internally nag himo sya ug thread ug eventhandler.

    back to your code, naay mali gamay na akong nakita na nganong mo kaging. gamay ra na problema, pero dako ni ug impact bai, especially na mag lost connection ang internet or hina ang connection or dako ang files na edownload.

    hope na nagkasinabot na ta ani...hahahahaha

  3. #43
    @ junkfactory
    I tried doing it like this. i hope sakto ra xa

    Button event in the UI
    private void button1_Click(object sender, EventArgs e)
    {
    object obj = webbrowser1.Document.InvokeScript("sampleScript");
    }
    Javascript
    function sampleScript() {
    //C# function call
    test();
    alert('ok');
    }
    Function equivalent to your GetString
    public void test()
    {
    WebClient sb = new WebClient();
    sb.DownloadStringCompleted += new
    DownloadStringCompletedEventHandler(sb_DownloadStr ingCompleted);
    sb.DownloadStringAsync(new Uri("http://www.google.com"));
    MessageBox.Show("1");
    }
    Download String Completed Event
    void sb_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
    MessageBox.Show("completed");
    }
    inig run ani ma display mn jd c "1" na messagebox then c "complete" daun.
    dli sd mo kaging ang UI thread.

    Althoug Async call xa, mo kaging xa kay nagwait ra mn ghapon xa sa DownLoadStringCompleted na event before mo continue xa sa next line sa javascript. So if dugay ang process mo kaging ra ghapon xa. unless there is a way to run InvokeScript in the background.

    sakto ba ako gbuhat junkfactory?
    lingaw kau imo project..daghan ta ma learn

  4. #44
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    artoy try dis... download and run --> hxxp://rapidshare.com/files/317897361/Debug_WebClient.rar

  5. #45
    Thanks Mark I will download that at home.

  6. #46
    Quote Originally Posted by Artoy View Post
    @ junkfactory
    I tried doing it like this. i hope sakto ra xa

    Button event in the UI


    Javascript


    Function equivalent to your GetString


    Download String Completed Event


    inig run ani ma display mn jd c "1" na messagebox then c "complete" daun.
    dli sd mo kaging ang UI thread.

    Althoug Async call xa, mo kaging xa kay nagwait ra mn ghapon xa sa DownLoadStringCompleted na event before mo continue xa sa next line sa javascript. So if dugay ang process mo kaging ra ghapon xa. unless there is a way to run InvokeScript in the background.

    sakto ba ako gbuhat junkfactory?
    lingaw kau imo project..daghan ta ma learn
    Yep sakto na Artoy. Karon imagina kung pila ka apps imo mahimo gamit ana nga idea = $$$

  7. #47
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Junkfactory, abi nako e upload nimo sample app... na imong gihimo base sa problem na to?

    kung madato ka artoy ayaw ko ug kalimti hehehehehe

  8. #48
    Aw, naka post naman gud si artoy sa code. nya pareha raman sila more or less. TY

  9. #49
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by junkfactory View Post
    Aw, naka post naman gud si artoy sa code. nya pareha raman sila more or less. TY

  10. #50
    Quote Originally Posted by junkfactory View Post
    Aw, naka post naman gud si artoy sa code. nya pareha raman sila more or less. TY
    Unsa gamit sa event nimo? Asa ako sabot mo signal siya ug event while download? Am I right?

    By the way, Imo na gi-check ang imong application gamit ug web debugger?
    Last edited by eax; 12-09-2009 at 09:30 PM.

  11.    Advertisement

Page 5 of 6 FirstFirst ... 23456 LastLast

Similar Threads

 
  1. love can be expressed in various ways
    By Meganda in forum "Love is..."
    Replies: 6
    Last Post: 08-27-2012, 04:53 AM
  2. Replies: 36
    Last Post: 04-11-2011, 09:13 PM
  3. Bidding Script - Would it be Possible in istorya.net
    By salbahis in forum Support Center
    Replies: 1
    Last Post: 02-02-2009, 11:49 AM
  4. how can i prevent from being spied in yahoo messenger?
    By boyq in forum Networking & Internet
    Replies: 21
    Last Post: 06-06-2008, 12:42 PM
  5. Replies: 3
    Last Post: 01-14-2008, 04:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top