异步后返回同步操作

时间:2017-02-13 12:01:27

标签: c# multithreading winforms

我有一个在4个线程上运行的方法,而主线程什么都不做:

    private void ConvThreadWorker(ConcurrentQueue<string> queue, ref ProgressData progData, ref ReferenceBool continued)
    {
        while (!queue.IsEmpty)
        {
            string file;
            if (queue.TryDequeue(out file))
            {
                ConvToG(file);
                UpdateUI(progData,queue.Count); //Using Control.Invoke(...)
            }
        }
        lock (continued)
        {
            if (!continued.Value)
            {
                continued.Value = true;
                PopulateControls(); //Run this on main thread
            }
        }
    }

然后一旦达到PopulateControls()方法,我想返回同步并在主线程上运行它(这不是一个长操作,所以不用担心阻塞)。

我将如何实现这一目标?

0 个答案:

没有答案