在WinForm中启动多线程的方法有以下几种:
使用Thread类启动线程:
Thread thread = new Thread(new ThreadStart(MethodName));
thread.Start();
使用ThreadPool类启动线程:
ThreadPool.QueueUserWorkItem(new WaitCallback(MethodName));
使用Task类启动线程:
Task.Run(() => MethodName());
使用BackgroundWorker组件启动线程:
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(MethodName);
worker.RunWorkerAsync();
其中,MethodName是需要在单独线程中执行的方法的名称。在这些方法中,可以执行耗时操作,而不会阻塞UI线程。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:winform多线程启动方法是什么