SetupDataRequest - error: "Index was outside the bounds of the array"

Eikon Api 1.8.4.0

Hi,

I have a function which tries to request the last 50 bars. It works fine most of the times, but sometimes when there is a new request, I get "Index was outside the bounds of the array" as error message back. Any idea why that is?

"INTU.O error with hist request:" System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at ThomsonReuters.Desktop.SDK.DataAccess.TimeSeries.Impl.RequestBase.RegisterCallbacks()
   at ThomsonReuters.Desktop.SDK.DataAccess.TimeSeries.Impl.RequestBase.SendRequest()
   at ThomsonReuters.Desktop.SDK.DataAccess.TimeSeries.Impl.DataRequest.Send()

Do I need to cancel something or reset something after I received the data back to clear the array again?

if(tSRequest == null)
tSRequest = DataServices.Instance.TimeSeries;

DateTime dt = DateTime.Now;
try
{
requestEikon = tSRequest.SetupDataRequest(ric)
.WithView("TRDPRC_1")
.WithAllFields()
.To(new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0))
.WithInterval(CommonInterval.Intraday1Minute)
.WithNumberOfPoints(50)
.OnDataReceived(TSDataReceivedCallback)
.WithTimeZone(TimezoneType.Instrument)
.CreateAndSend();
}
catch(Exception ex)
{
Console.WriteLine(ric + $" error with hist request: "+ ex);
return false;
}

Best Answer

  • Jirapongse
    Answer ✓

    @tt1057

    According to the answer on StackOverflow, multiple threads may access the dictionary concurrently.

    How does the application (on which thread) call the SetupDataRequest method? Is it the same thread that calls the OnDataServiceCreated callback method?



Answers

  • Thank you for the direction. Yes, it is a few timers which might have fired at the same time, that may caused this. I ammended that and also added a lock() before the SetupDataRequest call.

    I will test further if that fixes the issue

  • yes, I the lock() did the trick! thx for your support!