-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing ConfigureAwait(false) #1483
Comments
Hi @zzzprojects thanks for the heads up ☝ But the one you highlighted looks ok to me? It's an internal function, and inside that function the only await call DOES have Happy for you to send a pull request for any you find to discuss/review further |
That doesn't matter. The SendAsync method is asynchronous, and since you don't use ConfigureAwait(false) for this method, the UI will be blocked. So yes, the function inside (CloneHttpRequestMessageAsync) doesn't block the UI however, the line By example, this method in my WinForm application is blocked if I use your latest version. By just adding the ConfigureAway(false) everywhere it's now working. public static void CreateGist(string description, Dictionary<string, string> files)
{
var github = CreateClient();
// CREATE new gist
var newGist = new NewGist {Description = description, Public = true};
// ADD file
foreach (var file in files)
{
newGist.Files.Add(file.Key, file.Value);
}
// EXECUTE
var result = github.Gist.Create(newGist).Result;
} I may be wrong but a third party library should use ConfigureAwait(false) everywhere the await is used. Do you want me to put await & ConfigureAwait on the same line whenever is possible? I think there is only one place which I have to keep the multiline for readability. |
Yeah, I think this is a necessary evil of @zzzprojects I'm concerned that your code using |
The problem is right here. Since the library is missing a few ConfigureAwait and the API doesn't provide any non-asynchronous method, you force people to use an async method for not blocking the UI which is bad. Nop, I cannot provide any Using Using this example: // CREATE gist
CreateGist(description, files);
// DO something else after the gist has been created
DoSomethingElse(); Without With The user from the issue #1111 had the same problem as me. I'm pretty sure plenty of people tried your library and stopped because it was "not working". So yes, using |
Okay, now I'm confused.
Whether you call
I'm not sure I follow - if you're public static Task<Gist> CreateGist(string description, Dictionary<string, string> files)
{
var github = CreateClient();
// CREATE new gist
var newGist = new NewGist {Description = description, Public = true};
// ADD file
foreach (var file in files)
{
newGist.Files.Add(file.Key, file.Value);
}
// START TASK
return github.Gist.Create(newGist);
}
// note: this method can also be "async void" but returning
// a Task is nicer so that callers can await this too
public static async Task DoSomething()
{
// CREATE gist
var gist = await CreateGist(description, files);
// DO something else after the gist has been created
DoSomethingElse(gist);
} I'm not clear on the behaviour you're seeing - is it deadlocking, or just blocking the current thread? |
It's a deadlocking. The thread is deadlocked with the UI thread. Look at your code, you FORCED the user to use an async method and that's really bad. Most people doesn't understand how async method work, so that's why I avoid them. This is what I want: public static void CreateGist(string description, Dictionary<string, string> files)
{
var github = CreateClient();
// CREATE new gist
var newGist = new NewGist {Description = description, Public = true};
// ADD file
foreach (var file in files)
{
newGist.Files.Add(file.Key, file.Value);
}
// START and COMPLETE TASK
github.Gist.Create(newGist).Result;
}
public static DoSomething()
{
// CREATE gist
CreateGist(description, files);
// DO something else after the gist has been created
DoSomethingElse(gist);
} Imagine a legacy application where the What could have been few seconds changes by simply calling Anyway, from my part, I just downloaded the source and added all missing |
This is what I needed to hear. Thanks. If you're not interested in submitting a PR I'll add this to my task list for the week. |
I will be happy to do it tomorrow. All I need to know is the answer to the following question: Do you want me to put await & ConfigureAwait on the same line whenever is possible? I think there is only one place which I have to keep the multiline for readability. |
@zzzprojects single-line is preferred, yes |
In the issue #1111, we discussed on missing ConfigureAwait(false) which has been fixed in the pull #1248
However, I tried again your solution today, but there is still some ConfigureAwait missing like in the file HttpClientAdapter.SendAsync
should be
If you want, I can create a Pull Request. However, it only takes five mins to fix them all, so I'm not sure if you prefer to verify/fix it yourself.
The text was updated successfully, but these errors were encountered: