Answer the question
In order to leave comments, you need to log in
.NET - Collection Sharing?
The problem is this: there is a subscription to an event that updates the collection.
this.Trader.NewOrders += orders => this.GuiAsync(() => _ordersWindow.Orders.AddRange(orders)); //GuiAsync это аналог Dispatcher.BeginInvoke из фреймворка, с которым работаю
public void OnTimedEvent(object source, ElapsedEventArgs e)
{
if (MainWindow.Instance._tradesWindow.Trades[MainWindow.Instance._tradesWindow.Trades.Count() - 1].Time >= startTime)
{
var trade = MainWindow.Instance._tradesWindow.Trades[MainWindow.Instance._tradesWindow.Trades.Count() - 1];
if (trade.Price != Cc)
MainWindow.Instance.Dispatcher.BeginInvoke(new CheckNewStrikeA1Delegate(CheckNewStrikeA1), trade.Price);
}
}
void CheckNewStrikeA1(double strike)
{
lock (myLock2)
{
A1_P_51(strike);
}
if (IsNewTrade() == false) //эта функция смотрит в _ordersWindow.Orders
return;
Answer the question
In order to leave comments, you need to log in
Make common locks for adding, counting and checking, for example like this:
this.Trader.NewOrders += orders => this.GuiAsync(() => { lock(myLock2) { _ordersWindow.Orders.AddRange(orders); } }); //GuiAsync
void CheckNewStrikeA1(double strike)
{
lock (myLock2)
{
A1_P_51(strike);
if (IsNewTrade() == false) //эта функция смотрит в _ordersWindow.Orders
return;
}
}
not quite, just the opposite =) during the execution of the A1_P_51 function , the this.Trader.NewOrders event occurs and at the time of calling IsNewTrade _ordersWindow.Orders has already been changed, but IsNewTrade sees the “old” version of _ordersWindow.Orders , the one that was when CheckNewStrikeA1 was launched
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question