async-await

Async WCF call with ChannelFactory and CreateChannel

狂风中的少年 提交于 2019-12-31 22:25:11
问题 I work on project where web application hosted on web server calls WCF services hosted on the app server. Proxy for WCF calls is created by ChannelFactory and calls are made via channel, example: (omitting using block) var factory = new ChannelFactory<IUserService>(endpointConfigurationName); var channel = factory.CreateChannel(); var users = channel.GetAllUsers(); If I understand it well call via channel is async and thread on the web server is idle during request and just wait for a

CancellationToken with async Dapper methods?

为君一笑 提交于 2019-12-31 17:51:13
问题 I'm using Dapper 1.31 from Nuget. I have this very simple code snippet, string connString = ""; string query = ""; int val = 0; CancellationTokenSource tokenSource = new CancellationTokenSource(); using (IDbConnection conn = new SqlConnection(connString)) { conn.Open(); val = (await conn.QueryAsync<int>(query, tokenSource.Token)).FirstOrDefault(); } When I press F12 on QueryAsync , it points me to public static Task<IEnumerable<T>> QueryAsync<T> ( this IDbConnection cnn, string sql, dynamic

ASP.NET MVC 4 async child action

喜欢而已 提交于 2019-12-31 17:50:58
问题 I have an ASP.NET MVC 4 application targeting .NET 4.5. One of our child actions makes a call out to a web service using HttpClient. Since we're blocking on IO waiting for the HttpClient response, it makes a great deal of sense to convert the code to the async/await pattern. However, when MVC 4 attempts to execute the child action, we get the following error message: HttpServerUtility.Execute blocked while waiting for an asynchronous operation to complete. At first glance, it appears as

Async await how to use return values

南楼画角 提交于 2019-12-31 13:29:08
问题 I have a windows service that I have inherited from another developer, it runs very slow and has numerous slow call to the eBay API. I wish to speed it up without too much refactoring. I've just started to look at using c# async/await to try to get some of these slow call to run async. Here's what i'm trying to achieve: I have a 1 very busy method that makes lots of calls as below: getProducts getCategories getVehicles getImages My thoughts were that I could simply change the methods to async

Async await how to use return values

百般思念 提交于 2019-12-31 13:28:22
问题 I have a windows service that I have inherited from another developer, it runs very slow and has numerous slow call to the eBay API. I wish to speed it up without too much refactoring. I've just started to look at using c# async/await to try to get some of these slow call to run async. Here's what i'm trying to achieve: I have a 1 very busy method that makes lots of calls as below: getProducts getCategories getVehicles getImages My thoughts were that I could simply change the methods to async

async-await's continuations bursts — behave differently?

心不动则不痛 提交于 2019-12-31 13:13:37
问题 I have a winform code which run after a button click : void button1_Click(object sender, EventArgs e) { AAA(); } async Task BBB( int delay) { await Task.Delay(TimeSpan.FromSeconds(delay)); MessageBox.Show("hello"); } async Task AAA() { var task1 = BBB(1); // <--- notice delay=1; var task2 = BBB(1); // <--- notice delay=1; var task3 = BBB(1); // <--- notice delay=1; await Task.WhenAll(task1, task2, task3); } Question : Why do I see one MessageBox at a time when delay=1 : But If I change delay

Calling async method in controller

陌路散爱 提交于 2019-12-31 12:01:44
问题 I have a controller with something like the following: public MyController : Controller { public ActionResult DoSomething() { CallSomeMethodWhichDoesAsyncOperations(); return Json(new { success = successful }, JsonRequestBehavior.AllowGet); } } When calling my controller I get the following error: An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this

Correctly awaiting in F# an async C# method with return type of Task<T>

爷,独闯天下 提交于 2019-12-31 08:48:06
问题 I'd like to be able to consume a C# library from F#. Mostly this has been pretty straightforward. However, if I try to call a function that returns a Task<T> I am not able to get the returned value. So, I have C# method with the following definition: public async Task<TEvent> ReadEventAsync<TEvent>(string streamName, int position) where TEvent: class And I am trying to consume this method from F# as follows: let readEventFromEventStore<'a when 'a : not struct> (eventStore

Not much difference between ASP.NET Core sync and async controller actions

会有一股神秘感。 提交于 2019-12-31 07:56:46
问题 I wrote a couple of action methods in a controller to test the difference between sync and async controller actions in ASP.NET core: [Route("api/syncvasync")] public class SyncVAsyncController : Controller { [HttpGet("sync")] public IActionResult SyncGet() { Task.Delay(200).Wait(); return Ok(new { }); } [HttpGet("async")] public async Task<IActionResult> AsyncGet() { await Task.Delay(200); return Ok(new { }); } } I then load tested the sync end point: ... followed by the async end point: Here

How does compiler converts return value into return Task<value> in async methods?

老子叫甜甜 提交于 2019-12-31 07:41:49
问题 I've designed the following method to create records. public Task<Guid> NotAwaited() { Account account = new Account(); Context.Accounts.Add(account); Context.SaveChangesAsync(); return new Task<Guid>(() => account.Id); } Then, I realized that there's risk of the saving not being finished at the moment of returning the guid. So I've added await , which required me to decorate the method signature with async . Upon that, I got an error demanding a simpler syntax of what's being returned, like