aggregateexception

How to return AggregateException from async method

余生长醉 提交于 2020-05-24 04:07:09
问题 I got an async method working like an enhanced Task.WhenAll . It takes a bunch of tasks and returns when all are completed. public async Task MyWhenAll(Task[] tasks) { ... await Something(); ... // all tasks are completed if (someTasksFailed) throw ?? } My question is how do I get the method to return a Task looking like the one returned from Task.WhenAll when one or more tasks has failed? If I collect the exceptions and throw an AggregateException it will be wrapped in another

Parallel.Foreach loop, inconsistent behavior with explicit throw statement

那年仲夏 提交于 2019-12-31 02:43:10
问题 Created a simple program using Linqpad, where I am throwing an exception explicitly in the Parallel Foreach loop, which ideally shall be caught in the caller as Aggregate Exception , but when I explicitly throw the exception, it sometimes skip out few exceptions on random basis. I am not able to understand the behavior, anyone who can explain: void Main() { try { var intList = new List<int> {1,2,3,4,5,6}; Parallel.ForEach(intList, i => Test1(i)); } catch (AggregateException aggregateException

Keep UI responsive using Tasks, Handle AggregateException

烂漫一生 提交于 2019-12-13 16:46:25
问题 I have a problem with handling the AggregateException if my WinForms application starts a task to keep responsive while the task is performing. The simplified case is as follows. Suppose my Form has a fairly slow method, for instance: private double SlowDivision(double a, double b) { System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); if (b==0) throw new ArgumentException("b"); return a / b; } After pressing a button I want my form to show the result of SlowDivision(3,4). The following

HttpClient - dealing with aggregate exceptions

泄露秘密 提交于 2019-12-03 05:11:33
问题 Hi i am using HttpClient similar to this: public static Task<string> AsyncStringRequest(string url, string contentType) { try { var client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(contentType)); return client.GetStringAsync(url).ContinueWith(task => { return task.Result; }); } catch (AggregateException ex) { throw ex; } catch (WebException ex) { throw ex; } catch (Exception ex) { throw ex; } } But i am having

HttpClient - dealing with aggregate exceptions

瘦欲@ 提交于 2019-12-02 18:27:47
Hi i am using HttpClient similar to this: public static Task<string> AsyncStringRequest(string url, string contentType) { try { var client = new HttpClient(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(contentType)); return client.GetStringAsync(url).ContinueWith(task => { return task.Result; }); } catch (AggregateException ex) { throw ex; } catch (WebException ex) { throw ex; } catch (Exception ex) { throw ex; } } But i am having difficulties dealing with exceptions. I have added the additional catch blocks just to try and step throw,

Parallel.Foreach loop, inconsistent behavior with explicit throw statement

為{幸葍}努か 提交于 2019-12-02 01:14:55
Created a simple program using Linqpad, where I am throwing an exception explicitly in the Parallel Foreach loop, which ideally shall be caught in the caller as Aggregate Exception , but when I explicitly throw the exception, it sometimes skip out few exceptions on random basis. I am not able to understand the behavior, anyone who can explain: void Main() { try { var intList = new List<int> {1,2,3,4,5,6}; Parallel.ForEach(intList, i => Test1(i)); } catch (AggregateException aggregateException) { foreach (var ex in aggregateException.Flatten().InnerExceptions) { ex.Message.Dump(); } } } public

Flattening of AggregateExceptions for Processing

ぃ、小莉子 提交于 2019-11-29 03:07:59
I'm running into a few issues where I call flatten on an AggregateException , but inside there is still ANOTHER AggregateException ! This obviously means that they are being propagated up the chain and being rolled into another AggregateException . Is there a way to recursively flatten ALL inner AggregateExceptions? Usually, I'll use the handle delegate to process these, but it returns false if there is another inner AggregateExceeption. Am I not handling these properly? EDIT: Since I already am calling Flatten, it appears that the issue is that it's not being caught until way later in the

how to fix “'System.AggregateException' occurred in mscorlib.dll”

喜欢而已 提交于 2019-11-28 21:02:37
I receive such problem in debugger and program stops executing. Debugger doesn't show me the line so I don't know what to fix. An unhandled exception of type 'System.AggregateException' occurred in mscorlib.dll Additional information: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. Cannot obtain value of local or argument '' as it is not available at this instruction pointer, possibly because it has been optimized away. System.Threading.Tasks

Flattening of AggregateExceptions for Processing

徘徊边缘 提交于 2019-11-27 17:19:47
问题 I'm running into a few issues where I call flatten on an AggregateException , but inside there is still ANOTHER AggregateException ! This obviously means that they are being propagated up the chain and being rolled into another AggregateException . Is there a way to recursively flatten ALL inner AggregateExceptions? Usually, I'll use the handle delegate to process these, but it returns false if there is another inner AggregateExceeption. Am I not handling these properly? EDIT: Since I already

how to fix “'System.AggregateException' occurred in mscorlib.dll”

偶尔善良 提交于 2019-11-27 13:25:43
问题 I receive such problem in debugger and program stops executing. Debugger doesn't show me the line so I don't know what to fix. An unhandled exception of type 'System.AggregateException' occurred in mscorlib.dll Additional information: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. Cannot obtain value of local or argument '' as it is not available at this