0
下面是代碼示例,我希望隊列中的組件採取局部變量「實體」,我該如何執行此操作? THX如何將變量傳遞給Action?
private void DoComparison(StuffEntity entity)
{
try
{
bool dataFlag = CheckIsNewData(entity.PickingTime, entity.WarningPeriod);
if (dataFlag)
{
Queue<Action<StuffEntity>> queue = new Queue<Action<StuffEntity>>();
//How can I let the queue stuff take the entity?
queue.Enqueue(DelaySendingMessageOut);
if (!QueueItem.ContainsKey(entity.FridgeID))
{
QueueItem.Add(entity.FridgeID, queue);
}
}
}
catch (Exception ex)
{
CommonUnity.WriteLog(ex.Message);
CommonUnity.WriteLog(ex.StackTrace);
}
}
private void DelaySendingMessageOut(StuffEntity entity)
{
int pendingPeroid = entity.PendingTime.ToInt();
if (pendingPeroid <= 0)
pendingPeroid = 5;
Thread.Sleep(pendingPeroid * 60 * 1000);
TriggerCheckingBeforeSendMessageOut(entity);
}
目前尚不清楚什麼是你與隊列在做什麼?您已將該委託添加到隊列中,您打算如何調用它? –
'Action'將用於延遲調用該方法。所以你只會在需要調用的時候傳遞實例。如果你需要映射關係。除了'Queue'之外,您需要自定義集合來保存要傳遞的'Action'和'parameter' –