Your question itself has the answer, your task has not yet been evaluated—
Result = "{Not yet computed}. You need to give it more time, and check the result later. This time won't be known to you, since it is undefined amount of time.
That is because in the synchronous code you need to wait for the tasks
yourself. So to say, the code becomes,
var json = JsonConvert.SerializeObject(tblUserAgentSubAgentVMWithByte);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var result1 = client.PostAsync("api/Users/InsertUsers", content).Result;
Now, the result1 will contain the result of the request. Note that this will be a blocking call, so the thread will remain blocked—in waiting state—until your request is processed, and the response is captured.
The problem is, this is not an approach that I can recommend. Although you can mix sync and async code, and it is totally valid. Think of this,
var people = dbContext.GetPeople().Where(person => ).ToListAsync();;
foreach (var person in people) {
}
dbContext.SaveAsync();
The benefit of this is, that where you know there is a delay, take the job in the background, but in the cases where a context switch is more expensive, I recommend that you stay in the same thread, do the task and generate the response.
For this sake, I recommend that you continue to use the async patterns, and write the code in async fashion.
public async Task<ViewResult> Register(tblUserAgentSubAgentVM tblUserAgentSubAgentVM)
{
using (var client = new HttpClient())
{
string apiHost = "http://localhost:51522";
client.BaseAddress = new Uri(apiHost);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var json = JsonConvert.SerializeObject(tblUserAgentSubAgentVMWithByte);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var result1 = await client.PostAsync("api/Users/InsertUsers", content);
}
}
This way, now your runtime will automatically manage these tasks. Since you are using ASP.NET, it is way better and scalable to use async functions, than to bind the requests to threads. This is expensive. Please, do not do this.