Await works in console but does not in c# Library project

  • Thread starter Thread starter ExaCsharp
  • Start date Start date
E

ExaCsharp

Guest
Hello all,


I was working with HttpClient.PostAsync and couldn't test it line by line with visual studio 2017 it blocks in this line without any exception it just stops the test.

var response = await HttpClient.PostAsync(url, encodedContent).ConfigureAwait(false);


He is part of my code



[TestMethod()]
public void GetData()
{

/// Other code

MyClass object = new object(Params);
object.Methode1();

}

public void Methode1()
{
//Other code
Task.Run(() => DownloadPageAsync(param1, param2));

}

private async void DownloadPageAsync(string param1, string param2)
{
//Other code for parameters
HttpClient HttpClient = new HttpClient();
string page ="URL HERE";
var url = page;

var encodedContent = new FormUrlEncodedContent(parameters);
var response = await HttpClient.PostAsync(url, encodedContent).ConfigureAwait(false);

So what I did is that I tried to run nearly the same code and it did work in Console app.

Can someone explain to me what i am doing wrong please ?

Continue reading...
 
Back
Top