So the chart's RenderTarget (among other things SharpDX, ChartControl) get stomped on underneath the indicator that's doing the rendering. The same NT dispatch thread really should do the rendering and the state changes, otherwise there's no way for an indicator to know it's been terminated while in the middle of a render pass. No mutex or critical sections that can be created by an indicator can stop or even mitigate this.
The issue goes away entirely when the data provider is not connected automatically on startup, because nothing is getting terminated while it's in a render pass, which happens when the data provider connects.
Also, this conditions seems to only happen on startup. If in real-time, the data provider gets disconnected then reconnected, no issue. Again... race condition due to the processing load on startup.
Here are the relevant items from log my log and trace files.
2016-08-20 19:31:30:280|3|16|Chart rendering failed. There is likely a problem with a chart object's OnRender method. D2D error = 'Upgradeable lock may not be acquired with read lock held.'
2016-08-20 19:35:47:542 System.NullReferenceException: Object reference not set to an instance of an object.
at NinjaTrader.Data.Bars.GetNewBarsProxy(Bars barsProxy)
at System.Linq.Enumerable.WhereSelectArrayIterator`2. MoveNext()
at System.Collections.Generic.List`1.InsertRange(Int3 2 index, IEnumerable`1 collection)
at NinjaTrader.Gui.Chart.ChartControl.<>c__DisplayCla ss535_2.<RefreshIndicators>b__8(Object o)
at System.Threading.ExecutionContext.RunInternal(Exec utionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System. Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
EDIT -
Same scenario but one time today I got a different unhandled exception with 2 indicators on a chart:
2016-08-21 15:36:15:055 *************** unhandled exception trapped ***************
2016-08-21 15:36:15:055 Exception has been thrown by the target of an invocation.
2016-08-21 15:36:15:056 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.get_Item(Int32 index)
at NinjaTrader.Gui.Chart.ChartControl.ApplyNinjaScrip ts()
at System.Windows.Threading.Dispatcher.Invoke(Action callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout)
at System.Windows.Threading.Dispatcher.Invoke(Action callback)
at NinjaTrader.Gui.Chart.ChartControl.OnBarsToLoadCol lectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollectio n`1.OnCollectionChanged(NotifyCollectionChangedEve ntArgs e)
at System.Collections.ObjectModel.ObservableCollectio n`1.RemoveItem(Int32 index)
at System.Collections.ObjectModel.Collection`1.Remove (T item)
at NinjaTrader.Gui.Chart.ChartControl.<>c__DisplayCla ss478_1.<OnGetBarsCallback>b__0(Bars bars, ChartControl chartControl, ChartBars chartBars2)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeIn ternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Threading.ExceptionWrapper.Internal RealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatch When(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
Comment