async-await

Entity Framework 5 Thread Agility

筅森魡賤 提交于 2019-12-22 09:55:28
问题 A NullReferenceException deep inside EntityFramework code is thrown (EF bug?), but my question is about Entity Framework (v5) and WebAPI asynchronous controller action. A repro would be hard to recreate here, but the code in essence does the following: public class AController : ApiController { private IUow _uow; //among other things, a DbContext // DI ctor public AController(IUow uow) { _uow = uow; } [HttpPost] public async Task<HttpResponseMessage> Post(Model model) { Entity e = _uow.Entity

Why does assigning a value to an unused variable make a difference in the functionality of this async code?

旧时模样 提交于 2019-12-22 09:54:10
问题 I've got this code: private async Task SavePlatypusComplianceFileOnServer(string year, string month) { string monthAsMM = ReportRunnerConstsAndUtils.GetMonthAsMM(month); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(ReportRunnerConstsAndUtils.SERVER_BASE_ADDRESS); String uriToCall = String.Format("/api/PlatypusCompliance/{0}/{1}{2}", _unit, year, monthAsMM); HttpResponseMessage response = await client.PostAsync(uriToCall, null); } ...that works fine. On looking at it,

blocking collection process n items at a time - continuing as soon as 1 is done

前提是你 提交于 2019-12-22 09:33:06
问题 I have the following Scenario. I take 50 jobs from the database into a blocking collection. Each job is a long running one. (potentially could be). So I want to run them in a separate thread. (I know - it may be better to run them as Task.WhenAll and let the TPL figure it out - but I want to control how many runs simultaneously) Say I want to run 5 of them simultaneously (configurable) I create 5 tasks (TPL), one for each job and run them in parallel. What I want to do is to pick up the next

Ref in async Task

若如初见. 提交于 2019-12-22 09:26:56
问题 How I can to pass a reference as a parameter to Async method in Windows Store App ? I'm looking for something like this: var a = DoThis(ref obj.value); public async Task DoThis(ref int value) { value = 10; } But error: Async methods cannot have ref or out parameters Has any another way? Note: I need to pass exactly obj.value. This method would be used by different types of objects, by same type of objects, by one object, but I will pass obj.val_1, obj.val_2 or obj.val_10. All values will be

await and async blocking the UI

狂风中的少年 提交于 2019-12-22 09:09:51
问题 I wrote a little winforms application that search for files on the disk (what file is not that important for the sake of the question). the problem is the that it can be even 100,000 files or so. so this operation takes time. What I want to achieve is to do the search operation as an async operation and not to block the UI thread so the form won't get stuck. I can do this with the backgroundWorker but for some reason not with the async\await mechanism. Here is my code: private async void

C# multiple pinging in loop

北城余情 提交于 2019-12-22 08:41:37
问题 I need to create application which will be pinging multiple addresses in loop. I read a lot of examples here at stackoverflow and finally got working code: public void Check(List<string> addresses) { List<Task<PingReply>> pingTasks = new List<Task<PingReply>>(); foreach (string address in addresses) { pingTasks.Add(PingAsync(address)); } Task.Factory.ContinueWhenAll(pingTasks.ToArray(), _ => { }).ContinueWith(t => { StringBuilder pingResult = new StringBuilder(); foreach (var pingTask in

C# multiple pinging in loop

一个人想着一个人 提交于 2019-12-22 08:40:03
问题 I need to create application which will be pinging multiple addresses in loop. I read a lot of examples here at stackoverflow and finally got working code: public void Check(List<string> addresses) { List<Task<PingReply>> pingTasks = new List<Task<PingReply>>(); foreach (string address in addresses) { pingTasks.Add(PingAsync(address)); } Task.Factory.ContinueWhenAll(pingTasks.ToArray(), _ => { }).ContinueWith(t => { StringBuilder pingResult = new StringBuilder(); foreach (var pingTask in

Converting a IEnumerable<T> to IObservable<T>, with maximum parallelism

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 08:12:51
问题 I have a sequence of async tasks to do (say, fetch N web pages). Now what I want is to expose them all as an IObservable<T> . My current solution uses the answer from this question: async Task<ResultObj> GetPage(string page) { Console.WriteLine("Before"); var result = await FetchFromInternet(page); Console.WriteLine("After"); return result; } // pages is an IEnumerable<string> IObservable<ResultObj> resultObservable =pages.Select(GetPage). Select(t => Observable.FromAsync(() => t)).Merge(); /

System.Messaging - why MessageQueue does not offer an asynchronous version of Send

纵然是瞬间 提交于 2019-12-22 08:05:43
问题 Would anyone know why System.Messaging is not offering an asynchronous version of the Send method to send an MSMQ message to a queue. Actually there is asynchronous version of Peek and Receive methods (via Begin/End pairs that can be converted to a C#5 async awaitable method), but surprinsingly there is no BeginSend/EndSend methods offered, just a Send method which seems to me like it's a synchronous blocking I/O call. I think this is not a limitation of System.Messaging but rather one of the

is the below code captures the exceptions from original, continuation and child tasks in TPL?

可紊 提交于 2019-12-22 07:46:13
问题 I am using TPL and async/await to build async API on top of webclient for my applications. And few of the places (generally where I need to run bunch of async tasks and wait for all of them in the end), am following code snippet. I just want to make sure I get it correct as even though writing async code is relatively easy with TPL and async/await debugging/trouble shooting is still challenging (both interactive debugging and troubleshooting issues at customer site) - so want to get it right.