[英]Event reentry issue. Same event running concurrently
I have a event which in many case fires many times but I want an event to be completed before the next event is ran. 我有一个在很多情况下会触发多次的事件,但是我希望在下一个事件运行之前完成一个事件。
I am trying to create a cryptocurrency trading bot. 我正在尝试创建一个加密货币交易机器人。 The event in question is
private void CoinInformation_OnNewTradeEvent(object sender, AggregateTradeEventArgs e)
有问题的事件是
private void CoinInformation_OnNewTradeEvent(object sender, AggregateTradeEventArgs e)
Since that single event fires multiple times, I always thought it would be executed in a synchronous fashion where when one event is running, the next event wont run until this is completed. 由于单个事件会触发多次,因此我一直认为它将以同步方式执行,即当一个事件运行时,下一个事件将一直运行直到完成。 I tried putting locks but realize that doesnt work.
我试过把锁,但意识到那是行不通的。
private void CoinInformation_OnNewTradeEvent(object sender, AggregateTradeEventArgs e)
{
lock(myObject)
{
try
{
Decimal currentTradePrice = e.Trade.Price;
UpdateSMA(currentTradePrice);
TryBuy(currentTradePrice);
TrySell(currentTradePrice);
TryStopLoss(currentTradePrice);
}
catch
{
return;
}
}
}
抱歉,我的TryBuy和TrySell似乎不同步,我没有等他们,所以有重入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.