Windows通用应用程序线程

时间:2015-10-29 10:39:49

标签: c# windows-store-apps windows-10 win-universal-app

在我的通用Windows应用程序(Windows 10)中,我需要创建一个持续应用程序运行的整个时间的线程。 UI工作将在UI线程上执行,而某些任务将在队列中的单独线程中处理。 据我所知,Universal应用程序不支持System.Threading。 我读到了Threadpool,但我不明白它是如何解决我的目的的。

感谢所有帮助。

1 个答案:

答案 0 :(得分:0)

有关线程的详细信息,请访问this页面。 ThreadPool示例:

class Program
    {
        static void Main(string[] args)
        {
            ThreadPool.QueueUserWorkItem(new Program().testThread1);
            ThreadPool.QueueUserWorkItem(new Program().testThread2);

            Console.ReadLine();
        }

        public void testThread1(Object threadContext)
        {
            //executing in thread
            int count = 0;
            while (count++ < 10)
            {
                Console.WriteLine("Thread 1 Executed "+count+" times");
                Thread.Sleep(100);
            }
        }

        public void testThread2(Object threadContext)
        {
            //executing in thread
            int count = 0;
            while (count++ < 10)
            {
                Console.WriteLine("Thread 2 Executed " + count + " times");
                Thread.Sleep(100);
            }
        }
    }