我有一个奇怪的情况下,我无法找到我的错误的根源以下堆栈跟踪:布尔包括任务取消的异常而在C#做Parallel.Foreach
Message :One or more errors occurred.<br/>
StackTrace : at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)
at System.Threading.Tasks.Parallel.For(Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body)
代码本身是有一些逻辑简单明了Parallel.Foreach循环像下面:
Parllel.Foreach(_collection, new ParallelOptions { MaxDegreeOfParallelism =5 }, item=>
{
// code inside
});
可能是什么这个问题的根源?你们有什么提示给我,我应该在哪里寻找?
@mortb这是我的日志堆栈跟踪异常:
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Error.txt";
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
"" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
}
调试,并采取一看抛出的异常属性'InnerExceptions'(注意'InnerExceptions'的S)外的例外是刚刚超过一个的包装或几个抛出异常通过''// code inside''“,实际的异常被列在'InnerExceptions'中 – mortb
@mortb这就是我的错误..我无法将异常写入文本文件...等待我将显示你我如何记录错误.. – User987
@mortb你能看到我更新的问题吗?这就是我如何登录异常本身...有没有什么办法可以记录内部异常本身并查看哪条线会抛出它? – User987