locked
Handling Async Methods in WebService return large records RRS feed

  • Question

  • Say I have a webservice which has Async methods.

    How to handle below situations when calling this kind of web service

    1) what code I need to add to below code to handle this situation that this  async method in web service may take a while to return records?

    using Progress status indicator for this problem?

     

    2)in try-catch statement in below code, what http status should I look out for? Example : Fail, success, complete if there is an error or connection problem ?

    3) If there is connection issue over network AFTER a while reading records, how to get the last record returned?

       

    Thanks.

    private async void CallTaskTButton_Click(object sender, RoutedEventArgs e)
    {
        try
        {

       //--- call async methods of the webservice

         Task _asyncCustomer = Class1.Customer.Listing.GetAsyncRecords()


          foreach (wsCustomerList.Customer_List _List in _asyncCustomer.Result)
          {

            //-- code --

          }


        }
       catch(Exception ex)
       {

       }  
    }

     

    Wednesday, September 25, 2013 6:51 AM

Answers

  • I think that you've got a number of things to do here:

    1) On first startup, just display the Progress bar and launch the download on a background thread.

    2) If you're very concerned about network outage, then break up the download into chunks, and as each chunk is successfully downloaded, mark it off a list.  If you experience an outage during this time, then you don't have to start from the beginning.

    3) If you get any exception at all, just restart after the most recently downloaded chunk.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, September 27, 2013 1:46 PM
    Moderator

All replies

  • How long does it take to retrieve these records?  You might want to consider background transfer or virtualization.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, September 25, 2013 8:04 PM
    Moderator
  • Say we want to import data of rough estimate more 1000 of customer records and store them in SQLite Db. Thus, I need to handle the above mentioned situations. Would appreciate your help.  Thanks

    Thursday, September 26, 2013 12:57 AM
  • Is this a one-time thing or are you going to be doing this every time you use the app?  I'm not seeing your overall scenario here.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, September 26, 2013 4:09 PM
    Moderator
  • yes, this is one time kind of thing. We want to import all customers at one time after this we can move on to others tasks.

    Thus, I have the above mentioned concerns which I need to implement.

    Thanks

    Friday, September 27, 2013 3:08 AM
  • I think that you've got a number of things to do here:

    1) On first startup, just display the Progress bar and launch the download on a background thread.

    2) If you're very concerned about network outage, then break up the download into chunks, and as each chunk is successfully downloaded, mark it off a list.  If you experience an outage during this time, then you don't have to start from the beginning.

    3) If you get any exception at all, just restart after the most recently downloaded chunk.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, September 27, 2013 1:46 PM
    Moderator