configureawait

Why HttpContext.Current is not null in async/await with ConfigureAwait

荒凉一梦 提交于 2021-02-08 03:39:55
问题 I have a library async function called from controller. I expected HttpContext.Current to be null after await with ConfigureAwait(false) everywhere, but in controller it is not null. Can somebody explain why? //in libraby public class MyClass { public async Task WaitAsync() { await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); var httpContext = System.Web.HttpContext.Current; // null, OK } } public class HomeController : Controller { public async Task<ActionResult> Index() { var

Should I use ConfigureAwait(false) in places like Repository?

£可爱£侵袭症+ 提交于 2021-01-28 09:14:55
问题 Just read this article about ConfigureAwait and it made me think on an issue I haven't been able to come to peace with for some time now. Consider the code below. Each dependency uses await to make the call asynchronous. My concern is that each time we exit an await it goes back to the UI thread and I don't want that until I'm actually at the top level where the UI needs to be updated in order to reduce thread context switching. That made me think that ConfigureAwait(false) should be used in

Should I use ConfigureAwait(false) in places like Repository?

*爱你&永不变心* 提交于 2021-01-28 09:10:58
问题 Just read this article about ConfigureAwait and it made me think on an issue I haven't been able to come to peace with for some time now. Consider the code below. Each dependency uses await to make the call asynchronous. My concern is that each time we exit an await it goes back to the UI thread and I don't want that until I'm actually at the top level where the UI needs to be updated in order to reduce thread context switching. That made me think that ConfigureAwait(false) should be used in

Is ConfigureAwait(true) always get back to the orignial thread, even when the callee method does ConfigureAwait(false) internally? [duplicate]

爷,独闯天下 提交于 2020-12-31 05:49:15
问题 This question already has answers here : ConfigureAwait(true) not returning on the context it was awaited on (2 answers) Closed last month . I was expecting to get back to Thread#1 at location 1.2, but I did not. Is there a way to get back to UI thread after making the async call? Thanks Also I cannot make the top level method async. Not sure if async all the way will solve this issue but I don't have that choice right now. class Program { static void Main(string[] args) { ComputeThenUpdateUI

Is ConfigureAwait(true) always get back to the orignial thread, even when the callee method does ConfigureAwait(false) internally? [duplicate]

做~自己de王妃 提交于 2020-12-31 05:46:21
问题 This question already has answers here : ConfigureAwait(true) not returning on the context it was awaited on (2 answers) Closed last month . I was expecting to get back to Thread#1 at location 1.2, but I did not. Is there a way to get back to UI thread after making the async call? Thanks Also I cannot make the top level method async. Not sure if async all the way will solve this issue but I don't have that choice right now. class Program { static void Main(string[] args) { ComputeThenUpdateUI

Is ConfigureAwait(true) always get back to the orignial thread, even when the callee method does ConfigureAwait(false) internally? [duplicate]

馋奶兔 提交于 2020-12-31 05:45:27
问题 This question already has answers here : ConfigureAwait(true) not returning on the context it was awaited on (2 answers) Closed last month . I was expecting to get back to Thread#1 at location 1.2, but I did not. Is there a way to get back to UI thread after making the async call? Thanks Also I cannot make the top level method async. Not sure if async all the way will solve this issue but I don't have that choice right now. class Program { static void Main(string[] args) { ComputeThenUpdateUI

The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering

时光怂恿深爱的人放手 提交于 2020-06-27 17:20:06
问题 I am working on Dotnet Core Blazor and getting below error while using EventCallBack to bind the parent grid after delete events. Below the code for using Child component <tbody> @foreach (var employee in Employees) { <BlazorAppDemo.Pages.Controls.EmployeeList Employee="employee" ShowFooter="ShowFooter" OnEmployeeSelectionChange="onEmployeeSelectionChanged" btnDeleteClick="OnEmployeeDeleted" > </BlazorAppDemo.Pages.Controls.EmployeeList> } </tbody> EmployeeList child component is below <tr> @

Async methods with or without ConfigureAwait on NetStandard lib for Net Core

耗尽温柔 提交于 2019-12-23 04:36:35
问题 I have a library that is doing bulk insert. Library is EfCore extension made in .NetStandard(1.4) so it can be used in ASP.NET Core projects targeting both .NetCore(1.0+) or full NetFramework(4.6.1+) One of the functions is: public static BulkInsert<T>(this DbContext context, IList<T> entities) { SqlBulkOperation.InsertAsync<T>(context, entities); } internal static class SqlBulkOperation { public static void Insert<T>(DbContext context, IList<T> entities) { .... sqlBulkCopy.WriteToServer

Is ConfigureAwait(false) required on all levels of the async chain when no real I/O call is involved?

老子叫甜甜 提交于 2019-12-13 00:09:18
问题 Implementing a reusable adaptor type of library on top of Azure Document Db Client SDK. The library can run anywhere, not only in an ASP.NET Core web service, but in a command line app, ASP.NET Web Api etc. In this library all methods are async and they are simply layers of abstraction that makes it easier to use Document Db client api s. The only real async call - I/O request - is actually done on the lowest layer by the api s from the Document Db SDK. Any code above that I wrote is just in

How to correctly block on async code?

心不动则不痛 提交于 2019-12-09 16:57:44
问题 I have tons of code written in following manner: public string SomeSyncOperation(int someArg) { // sync code SomeAsyncOperation(someArg, someOtherArg).ConfigureAwait(false).GetAwaiter().GetResult() // sync code }; Here we have some sync code that have to access to async api, so it blocks until results are ready. We can't method change signature and add async here. So, we are waiting synchronously anyway, so do we need ConfigureAwait(false) here? I'm pretty sure that we don't, but I'm a bit