async-await

How to resolve “ 'IAsyncActionWithProgress<>' is defined in an assembly that is not referenced” in Windows UAP app

ぃ、小莉子 提交于 2019-12-21 12:21:43
问题 I am developing a Windows UAP app in Visual Studio Ultimate CTP 2015 (latest one available in site). I am facing issues while using await on Functions returning IAsyncActionWithProgress<>, IAsyncAction<> , IAsyncOperation<> and IAsyncOperationWithProgress<>. I am getting the following error Error CS0012 The type 'IAsyncActionWithProgress<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken

Parallel.ForEach vs Async Forloop in Heavy I/O Ops

我们两清 提交于 2019-12-21 12:21:25
问题 I want to compare two theoretical scenarios. I have simplified the cases for purpose of the question. But basically its your typical producer consumer scenario. (I'm focusing on the consumer). I have a large Queue<string> dataQueue that I have to transmit to multiple clients. So lets start with the simpler case: class SequentialBlockingCase { public static Queue<string> DataQueue = new Queue<string>(); private static List<string> _destinations = new List<string>(); /// <summary> /// Is the

Is Task.WhenAll required in the sample code?

最后都变了- 提交于 2019-12-21 12:17:59
问题 In the following code task1 and task2 are independent of each other and can run in parallel. What is the difference between following two implementations? var task1 = GetList1Async(); var task2 = GetList2Async(); await Task.WhenAll(task1, task2); var result1 = await task1; var result2 = await task2; and var task1 = GetList1Async(); var task2 = GetList2Async(); var result1 = await task1; var result2 = await task2; Why should I choose one over the other? Edit: I would like to add that return

How do I “.Wait( )” on a ConfiguredTaskAwaitable?

随声附和 提交于 2019-12-21 10:48:52
问题 Given the following extension to prevent Tasks from blocking the UI Thread ( probably not the exact correct terminology but whatever ) : public static ConfiguredTaskAwaitable DontBlock( this Task T ) { return T.ConfigureAwait( false ); } public static ConfiguredTaskAwaitable<T> DontBlock<T>( this Task<T> T2 ) { return T2.ConfigureAwait( false ); } In some cases ( such as if I need to call an awaitable within an object constructor, or if I need to call .Wait( ) from a WinForms Program.Main( )

Check if Action is async lambda

ⅰ亾dé卋堺 提交于 2019-12-21 10:03:28
问题 Since I can define an Action as Action a = async () => { }; Can I somehow determine (at run time) whether the action a is async or not? 回答1: No - at least not sensibly. async is just a source code annotation to tell the C# compiler that you really want an asynchronous function/anonymous function. You could fetch the MethodInfo for the delegate and check whether it has an appropriate attribute applied to it. I personally wouldn't though - the need to know is a design smell. In particular,

Where does an async Task throw Exception if it is not awaited?

你。 提交于 2019-12-21 09:10:12
问题 I have the following example: (please also read comments in code, as it will make more sense ) public async Task<Task<Result>> MyAsyncMethod() { Task<Result> resultTask = await _mySender.PostAsync(); return resultTask; // in real-life case this returns to a different assembly which I can't change // but I need to do some exception handling on the Result in here } let's assume the PostAsync method of _ mySender looks like this: public Task<Task<Result>> PostAsync() { Task<Result> result =

Is it okay to attach async event handler to System.Timers.Timer?

假如想象 提交于 2019-12-21 09:09:21
问题 I have already read SO post here and article here I have a timer event that fires every once in a while and i want to do some asynchronous processing inside the handler, so something along the lines of: Timer timer = new Timer(); timer.Interval = 1000; timer.Elapsed += timer_Elapsed; // Please ignore this line. But some answers already given based on this line so I will leave it as it is. timer.Elapsed += async (sender, arguments) => await timer_Elapsed(sender, arguments); private async Task

Can ConfigureAwait(false) in a library lose the synchronization context for the calling application?

冷暖自知 提交于 2019-12-21 08:23:59
问题 I've read the advice many times from people smarter than me, and it has few caveats: Always use ConfigureAwait(false) inside library code . So I'm fairly certain I know the the answer, but I want to be 100%. The scenario is I have a library that thinly wraps some other asynchronous library. Library code: public async Task DoThingAsyc() { // do some setup return await otherLib.DoThingAsync().ConfigureAwait(false); } Application code: // need to preserve my synchronization context await myLib

Can ConfigureAwait(false) in a library lose the synchronization context for the calling application?

青春壹個敷衍的年華 提交于 2019-12-21 08:23:11
问题 I've read the advice many times from people smarter than me, and it has few caveats: Always use ConfigureAwait(false) inside library code . So I'm fairly certain I know the the answer, but I want to be 100%. The scenario is I have a library that thinly wraps some other asynchronous library. Library code: public async Task DoThingAsyc() { // do some setup return await otherLib.DoThingAsync().ConfigureAwait(false); } Application code: // need to preserve my synchronization context await myLib

MongoError: server instance pool was destroyed

不问归期 提交于 2019-12-21 07:46:47
问题 I built this app with the help of this question I did previously. app.js : var mongolib = require('./middlewares/db.js'); var downloaderCoverageWho = require('./routers/downloaderCoverageWho.js'); var downloaderCoverageIta = require('./routers/downloaderCoverageIta.js'); const start = async function() { const conn = await mongolib.connectToMongoDb(); const coverages = await mongolib.createACollection('coverages'); const isPageHasUpdates = true; if(isPageHasUpdates) { await downloadCoverageIta