簡體   English   中英

排隊函數未與出隊執行

[英]Queued function not executing with dequeue

出隊不調用排隊函數,控制台顯示有1個操作排隊。

這段代碼:

private static Queue<Action> changeMaterialTask = new Queue<Action>();

static void Main(string[] args)
{
    AddAction(() => Test());
    while (changeMaterialTask.Count > 0)
    {
        Console.WriteLine("About to deque");
        changeMaterialTask.Dequeue();
        Console.WriteLine("I've dequeued");
    }
}

public static void AddAction(Action task)
{
    changeMaterialTask.Enqueue(task);
}

public static void Test()
{
    Console.WriteLine("Worked");
}

當隊列功能在出隊時執行時,在控制台“工作”上打印。

Queue<T>.Dequeue方法返回從隊列中出隊的項目,在這種情況下為Action 然后,您需要對此進行處理,例如:

var action = changeMaterialTask.Dequeue();
action();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM