task-parallel-library

Queuing BankgroundJob with Hangfire within an async action in ASP.NET MVC freeze the application

雨燕双飞 提交于 2019-12-24 03:30:03
问题 I have this action on one of my controllers which is called by another method which has been called also by another action. All works fine, unless I try to en-queue with Hangfire some jobs: _bankClient.FetchAndEnsureTransactionsAsync and _bankClient.RefreshItemAsync . This is causing the application to freeze (the client, browser, stops while the server is still running). I suppose is some weird deadlock , but nothing I've tried seems to make it work! Would someone know how to solve this

Trying to call Async method synchronously. It waits on Task.Result forever [duplicate]

喜夏-厌秋 提交于 2019-12-24 03:12:51
问题 This question already has answers here : Synchronously waiting for an async operation, and why does Wait() freeze the program here (4 answers) Closed 5 years ago . So I'm writing an application in which I want to expose a series of methods with both synchronous and asynchronous equivalents. To do this, I figured the easiest approach was to write the logic in the asnyc method, and write synchronous methods as wrappers around the async methods, waiting synchronously for them to deliver their

Trying to call Async method synchronously. It waits on Task.Result forever [duplicate]

泄露秘密 提交于 2019-12-24 03:12:03
问题 This question already has answers here : Synchronously waiting for an async operation, and why does Wait() freeze the program here (4 answers) Closed 5 years ago . So I'm writing an application in which I want to expose a series of methods with both synchronous and asynchronous equivalents. To do this, I figured the easiest approach was to write the logic in the asnyc method, and write synchronous methods as wrappers around the async methods, waiting synchronously for them to deliver their

How to create a generic Task.ContinueWith extension method

泪湿孤枕 提交于 2019-12-24 02:54:05
问题 So currently I have a Task.ContinueWith extensions method like so: public static Task ContinueWith_UsingSyncContextWorkaround(this Task task, Action<Task> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler, SynchronizationContext sc) { Action<Task> actionWithWorkaround = t => { SynchronizationContext.SetSynchronizationContext(sc); continuationAction(t); }; return task.ContinueWith(actionWithWorkaround,

Is it possible to have a method using Parallel tasks and returns IEnumerable<T>

人走茶凉 提交于 2019-12-24 02:43:09
问题 I want that the method executes tasks in parallel and when the task is finished "yield return" the result. Is it possible to have something like that : public IEnumerable<string> GetAllLogs() { var computers = GetComputers() .Where(cpt => cpt.IsOnline); Parallel.ForEach(computers, c => c.GetLogs()); // How to 'yield return' ? } Thx !!! EDIT : Maybe my previous sample was not enough explicit here a new and (I hope) more explicit one ;-) I want to know how to parallize the GetAllLogs method :

Is it possible to have a method using Parallel tasks and returns IEnumerable<T>

不羁岁月 提交于 2019-12-24 02:43:06
问题 I want that the method executes tasks in parallel and when the task is finished "yield return" the result. Is it possible to have something like that : public IEnumerable<string> GetAllLogs() { var computers = GetComputers() .Where(cpt => cpt.IsOnline); Parallel.ForEach(computers, c => c.GetLogs()); // How to 'yield return' ? } Thx !!! EDIT : Maybe my previous sample was not enough explicit here a new and (I hope) more explicit one ;-) I want to know how to parallize the GetAllLogs method :

Task.IsCancelled doesn't work

大城市里の小女人 提交于 2019-12-24 01:39:09
问题 I've got the following sample code: static class Program { static void Main() { var cts = new CancellationTokenSource(); var task = Task.Factory.StartNew( () => { try { Console.WriteLine("Task: Running"); Thread.Sleep(5000); Console.WriteLine("Task: ThrowIfCancellationRequested"); cts.Token.ThrowIfCancellationRequested(); Thread.Sleep(2000); Console.WriteLine("Task: Completed"); } catch (Exception exception) { Console.WriteLine("Task: " + exception.GetType().Name); throw; } }).ContinueWith(t

How does Task Parallel Library scale on a terminal server or in a web application?

女生的网名这么多〃 提交于 2019-12-24 01:29:10
问题 I understand that the TPL uses work-stealing queues for its tasks when I execute things like Parallel.For and similar constructs. If I understand this correctly, the construct will spin up a number of tasks, where each will start processing items. If one of the tasks complete their allotted items, it will start stealing items from the other tasks which hasn't yet completed theirs. This solves the problem where items 1-100 are cheap to process and items 101-200 are costly, and one of the two

Depth first search in a distributed way

泄露秘密 提交于 2019-12-24 01:19:46
问题 I have tried implementing depth first search in c# but I am not exactly sure how to do this the distributed computing way. If you guys can help me out in this i would be really grateful :) You can find my DFS code below public class DFS { static List<string> traversedList = new List<string>(); static List<string> parentList = new List<string>(); public static void Main(string[] args) { int N = 100; int M = N * 4; int P = N * 16; Stack newstack = new Stack(); List<string> global_list=new List

nUnit Assert.That delegate concurrency issue

馋奶兔 提交于 2019-12-24 01:07:51
问题 I am experiencing some temporary dead lock in my code and can't wrap my head around it. Simple code (I cannot create a simple call chain to reproduce the code in InvokeChangeEvent ) [Test] public async void Test() { sut.InvokeChangeEvent("./foo.file"); // Event is handled by an async handler chaining multiple await resulting in a file write // await Task.Delay(3000); Assert.That(() => Directory.GetFiles("some dir").Count(), Is.EqualTo(3).After(15000, 300)); } I am aware that y'all (:D) want