Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting result of a task
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Common Language Runtime
Title:
Getting result of a task
Environment versions
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Miscellaneous
Thread ID:
01643645
Message ID:
01643645
Views:
73
Hi everybody,

I've defined the following method:
static async Task<HttpResponseMessage> GetResponse(TicketUsageRequests ticket, string apiUrl)
        {
            HttpResponseMessage response = await client.PostAsJsonAsync(apiUrl, ticket);
            //response.EnsureSuccessStatusCode();
            
            return response;
        }
My question is - how can I get its result in the main method code and synchronously?

My current method is:
try
            {               
                SetRequestHeaders(tcHost, tcUserName, tcPassword, tnTimeout, tnRetries);

                TicketUsageRequests ticket = new TicketUsageRequests();
                ticket.TicketBarcode = tcBarcode;
                ticket.TicketUsageDate = tcUsageDate;
                ticket.UserID = tcUserName;

               ... here I want to get the result of the response and parse it

   ...
I found this

http://stackoverflow.com/questions/5095183/how-would-i-run-an-async-taskt-method-synchronously

and trying to figure out how to apply pixel's solution.

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform