task
System.Threading.Tasks – Limit the number of concurrent Tasks
I know this is almost a year old, but I have found a much easier way to achieve this, so I thought I would share: Dim actionsArray() As Action = new Action(){ New Action(Sub() DoComputation1()), New Action(Sub() DoComputation2()), … New Action(Sub() DoComputation100()) } System.Threading.Tasks.Parallel.Invoke(New Tasks.ParallelOptions() With {.MaxDegreeOfParallelism = 5}, actionsArray) Voila!
IRequestHandler return void
Generally speaking, if a Task based method does not return anything you can return a completed Task public Task Handle(CreatePersonCommand message, CancellationToken cancellationToken) { return Task.CompletedTask; } Now, in MediatR terms a value needs te be returned. In case of no value you can use Unit: public Task<Unit> Handle(CreatePersonCommand message, CancellationToken cancellationToken) { return Task.FromResult(Unit.Value); … Read more
Return list from async/await method
You need to correct your code to wait for the list to be downloaded: List<Item> list = await GetListAsync(); Also, make sure that the method, where this code is located, has async modifier. The reason why you get this error is that GetListAsync method returns a Task<T> which is not a completed result. As your … Read more
Celery: How to ignore task result in chord or chain?
There is a built-in functionality to ignore result in chaining and others – immutable subtask. You can use .si() shortcut instead of .s() or .subtask(immutable=True) More details here: http://docs.celeryproject.org/en/master/userguide/canvas.html#immutability
What happens while waiting on a Task’s Result?
In Windows, all I/O is asynchronous. Synchronous APIs are just a convenient abstraction. So, when you use HttpWebRequest.GetResponse, what actually happens is the I/O is started (asynchronously), and the calling thread (synchronously) blocks, waiting for it to complete. Similarly, when you use HttpClient.PostAsync(..).Result, the I/O is started (asynchronously), and the calling thread (synchronously) blocks, waiting … Read more
How can I run both of these methods ‘at the same time’ in .NET 4.5?
Here is what you may want to do: public async Task<PewPew> SomeMethod(Foo foo) { // get the stuff on another thread var cTask = Task.Run(() => GetAllTheCats(foo)); var fTask = Task.Run(() => GetAllTheFood(foo)); var cats = await cTask; var food = await fTask; return new PewPew { Cats = cats, Food = food }; } … Read more
App always starts fresh from root activity instead of resuming background state (Known Bug) [duplicate]
This is due to the intents being used to start the app being different. Eclipse starts an app using an intent with no action and no category. The Launcher starts an app using an intent with android.intent.action.MAIN action and android.intent.category.LAUNCHER category. The installer starts an app with the android.intent.action.MAIN action and no category. Whoever submitted … Read more
Python – What is queue.task_done() used for?
Queue.task_done is not there for the workers’ benefit. It is there to support Queue.join. If I give you a box of work assignments, do I care about when you’ve taken everything out of the box? No. I care about when the work is done. Looking at an empty box doesn’t tell me that. You and … Read more
Set ApartmentState on a Task
When StartNew fails you just do it yourself: public static Task<T> StartSTATask<T>(Func<T> func) { var tcs = new TaskCompletionSource<T>(); Thread thread = new Thread(() => { try { tcs.SetResult(func()); } catch (Exception e) { tcs.SetException(e); } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); return tcs.Task; } (You can create one for Task that will look almost identical, or add … Read more