0

below is the code sample, I want the components in the queue to take the local variable "entity", how can I achive this? thx

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);
    }
4

1 回答 1

0
queue.Enqueue((e) => DelaySendingMessageOut(entity));

But you can use Queue<Action> since you will not use the argument e:

Queue<Action> queue = new Queue<Action>();
queue.Enqueue(() => DelaySendingMessageOut(entity));
于 2013-10-15T08:41:58.977 回答