Multi Threading for asynchronous call

Last post 07-09-2009 7:02 AM by new Bie. 0 replies.

Sort Posts:

  • Multi Threading for asynchronous call

    07-09-2009, 7:02 AM
    • Member
      point Member
    • new Bie
    • Member since 04-07-2009, 2:38 AM
    • Posts 15

    My program flow would be like this :

    n=1,2,3,4,5.....Max=50

    page_Demo.aspx ?type=a&count=n                will be called and it will return an xmldocument having an attribute of isEndOfFile which      will decide wether to call for that particular type again with increasing value of n

    page_Demo.aspx?type=b&count=n        same will be the case with type=b and more

                                                         so with in each type(ex - a,b,c,d...) there will be dependency on next call with increasing value of n

                                                             but with different value of type we want asynchronous behaviour

     

    now i am  doing:

     

     string s = string.Empty;

    bool eof = false;

    protected void Page_Load(object sender, EventArgs e)

    {

     Thread  thread = new Thread(ThreadJob);

    Thread thread1 = new Thread(ThreadJob);

    thread.Start("prp");

     thread1.Start("prj");

     }

      

    private void ThreadJob(object type)

    {

    switch (type.ToString())

    case "prp":

          for (int i = 1; i < 15; i++)

    {

    if (!eof)

    {

    WebClient wc = new WebClient();

    wc.DownloadStringAsync(new Uri("http://localhost/Trial_Cache/AsyncCalled.aspx?type=" + type.ToString() + "&cnt=" + i.ToString()));

    wc.DownloadStringCompleted +=new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);

    Thread.Sleep(100);

    }

    else

    {

     break;

    }

    }

    break;

     

    case "prj":

    for (int i = 1; i < 15; i++)

    {

    if (!eof)

    {WebClient wc2 = new WebClient();

     wc2.DownloadStringAsync(new Uri("http://localhost:5825/Trial_Cache/AsyncCalled.aspx?type=" + type.ToString() + "&cnt=" + i.ToString()));

    wc2.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc2_DownloadStringCompleted);

    Thread.Sleep(100);

    }else

    {

    break;

    }

    }

    break;

    }

     

    private void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)

    {//assigning the value of eof from the the xml document returned from the aspx page

    }

    private void wc2_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)

    {

    //assigning the value of eof from the the xml document returned from the aspx page

    }

     *************************************************************

    problem is that it is being called more times even after it called eof May be the time asynchronous behavior with in type also

    so what neds to be done

     

Page 1 of 1 (1 items)