なぜ今日受け取ったのか理解できませんSystem.IndexOutOfRangeException
。プログラムがすでに 8 時間動作していて、例外が発生した場所が何百万回も実行されたときに、それを受け取りました。この場所は非常に単純です。
for (int i = 0; i < _goldDesiredOrdersBuy.Length; i++)
{
_goldDesiredOrdersBuy[i] = -1; // IndexOutOfRangeException! Strategy3.cs:line 666
}
プログラムの開始時に _goldDesiredOrdersBuy を 1 回だけ初期化するので、例外が発生したときに初期化されることが保証されます。
private int[] _goldDesiredOrdersBuy = new int[MaxOrderbookDepth];
この配列に触れる場所がもう 1 つあります。
private int GetGoldVolumeBuy(int bidQuotesPos)
{
if (_goldDesiredOrdersBuy[bidQuotesPos] > -1)
{
return _goldDesiredOrdersBuy[bidQuotesPos];
}
int result = GetGoldVolumeBuyNotCached(bidQuotesPos);
_goldDesiredOrdersBuy[bidQuotesPos] = result;
return result;
}
それだけです。_goldDesiredOrdersBuy
アプリケーションの起動時に一度初期化され、初期化されることが保証され、配列の長さがどこにも変更されていないため、どのように受け取ったのかわかりませんIndexOutOfRangeException
。何か考えはありますか?
Unhandled Exception: System.AggregateException: 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. --->
System.AggregateException: One or more errors occurred. --->
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at MyProj.Strategies.Strategy3.CalculateNewDesiredOrdersBuy() in C:\Oleg\projects\MyProj\MyProj\Strategies\Strategy3.cs:line 666
at MyProj.Strategies.Strategy3.RecalculateBuyOrders() in C:\Oleg\projects\MyProj\MyProj\Strategies\Strategy3.cs:line 567
at MyProj.Strategies.Strategy3.OnAllTablesUpdated() in C:\Oleg\projects\MyProj\MyProj\Strategies\Strategy3.cs:line 499
at MyProj.Strategies.Strategy3.AllTablesUpdated() in C:\Oleg\projects\MyProj\MyProj\Strategies\Strategy3.cs:line 413
at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
at System.Threading.Tasks.Task.<>c__DisplayClass7.<ExecuteSelfReplicating>b__6(Object )
--- End of inner exception stack trace ---
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.ForEachWorker[TSource,TLocal](IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)
at System.Threading.Tasks.Parallel.ForEach[TSource](IEnumerable`1 source, Action`1 body)
at MyProj.Market.FinishUpdatingTables() in C:\Oleg\projects\MyProj\MyProj\Market.cs:line 449
at Library.Exchange.Gate.DoGateIteration() in C:\Oleg\projects\MyProj\MyProj\Gate.cs:line 143
at Library.Exchange.Gate.<Connect>b__0() in C:\Oleg\projects\MyProj\MyProj\Gate.cs:line 98
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
at System.Threading.Tasks.TaskExceptionHolder.Finalize()