Click here to Skip to main content
15,889,877 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Pete O'Hanlon22-Mar-17 2:03
mvePete O'Hanlon22-Mar-17 2:03 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier22-Mar-17 2:08
professionalNathan Minier22-Mar-17 2:08 
SuggestionRe: How to write a generic code to make async call to Rest Service Pin
Richard Deeming22-Mar-17 2:23
mveRichard Deeming22-Mar-17 2:23 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
ArunHanu22-Mar-17 3:06
ArunHanu22-Mar-17 3:06 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier22-Mar-17 3:53
professionalNathan Minier22-Mar-17 3:53 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Richard Deeming22-Mar-17 4:20
mveRichard Deeming22-Mar-17 4:20 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier22-Mar-17 4:59
professionalNathan Minier22-Mar-17 4:59 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Richard Deeming22-Mar-17 5:26
mveRichard Deeming22-Mar-17 5:26 
But that's the point - it WILL behave in an asynchronous manner! Smile | :)
C#
public async Task<List<todoitem>> RefreshDataAsync ()
{
    Items = new List<todoitem> ();
    RestUrl = "http://localhost:9054/TotoItem"
    var uri = new Uri (string.Format (RestUrl, string.Empty));
    
    try {
        // Runs synchronously up to here...
        var response = await client.GetAsync (uri);
        
        // The rest of the method is signed up as a continuation,
        // invoked when the IO completion port notifies that the request has been completed.
        // The current thread is NOT blocked.
        
        // Depending on the calling context, the continuation MIGHT run on the same thread as the caller.
        // But this is handled asynchronously; the thread does not block waiting to run the continuation.
        // This can be changed by adding ".ConfigureAwait(false)" after "GetAsync(url)".
        
        if (response.IsSuccessStatusCode) {
            var content = await response.Content.ReadAsStringAsync ();
            // Again, the rest of the method is signed up as a continuation.
            // The thread is NOT blocked waiting for the response content to be downloaded.
            
            Items = JsonConvert.DeserializeObject <List<todoitem>> (content);
            // The JSON conversion IS run syncronously.
            // But async support in JSON.NET was only recently added (v10.1), so there's probably no option here.
    }
    } catch (Exception ex) {
        Debug.WriteLine (@" ERROR {0}", ex.Message);
    }
    
    return Items;
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier22-Mar-17 6:06
professionalNathan Minier22-Mar-17 6:06 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Richard Deeming22-Mar-17 6:16
mveRichard Deeming22-Mar-17 6:16 
GeneralRe: How to write a generic code to make async call to Rest Service Pin
Nathan Minier23-Mar-17 1:12
professionalNathan Minier23-Mar-17 1:12 
QuestionWindows 10 Thin Border Cause a space issue compare to windows 8 Pin
Member 979968321-Mar-17 20:12
Member 979968321-Mar-17 20:12 
AnswerRe: Windows 10 Thin Border Cause a space issue compare to windows 8 Pin
Gerry Schmitz23-Mar-17 17:52
mveGerry Schmitz23-Mar-17 17:52 
QuestionGetting COM port list ? Pin
Member 245846721-Mar-17 16:44
Member 245846721-Mar-17 16:44 
AnswerRe: Getting COM port list ? Pin
Richard MacCutchan21-Mar-17 23:11
mveRichard MacCutchan21-Mar-17 23:11 
GeneralRe: Getting COM port list ? Pin
Member 245846722-Mar-17 15:28
Member 245846722-Mar-17 15:28 
AnswerRe: Getting COM port list ? Pin
Ralf Meier23-Mar-17 1:26
mveRalf Meier23-Mar-17 1:26 
AnswerRe: Getting COM port list ? Pin
Gerry Schmitz23-Mar-17 17:51
mveGerry Schmitz23-Mar-17 17:51 
QuestionDCMTK help needed Pin
Tetsuo_DarkK21-Mar-17 4:49
Tetsuo_DarkK21-Mar-17 4:49 
AnswerRe: DCMTK help needed Pin
Richard MacCutchan21-Mar-17 4:56
mveRichard MacCutchan21-Mar-17 4:56 
QuestionQuick MEF Question Pin
Kevin Marois20-Mar-17 7:04
professionalKevin Marois20-Mar-17 7:04 
AnswerRe: Quick MEF Question Pin
Richard MacCutchan20-Mar-17 23:02
mveRichard MacCutchan20-Mar-17 23:02 
GeneralRe: Quick MEF Question Pin
Kevin Marois21-Mar-17 4:03
professionalKevin Marois21-Mar-17 4:03 
AnswerRe: Quick MEF Question Pin
Nathan Minier21-Mar-17 1:18
professionalNathan Minier21-Mar-17 1:18 
AnswerRe: Quick MEF Question Pin
Pete O'Hanlon21-Mar-17 4:31
mvePete O'Hanlon21-Mar-17 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.