后台工作进程或线程? [英] Background Worker Process or Thread?

查看:77
本文介绍了后台工作进程或线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Winform应用程序,该应用程序在gridview中列出了一批发票.用户选择批次,然后单击按钮生成发票".该过程大约需要4-5分钟.在运行时,我将有一个选取框进度栏,并希望禁用所有按钮.

I have a Winform app which lists a batch of invoices in a gridview. The users select the batch and clicks a button, "Generate Invoices". The process takes about 4-5 mins. While this is running I will have a marquee progress bar and would like to disable all buttons.

我应该使用BackgroundWorker进程还是创建一个新线程来运行此任务?

Should I use a BackgroundWorker Process or create a new thread to run this task?

推荐答案

这是BackgroundWorker的确切任务类型.您应该将其推送到后台工作程序中,然后让其运行.这提供了一种更新进度条等的简单方法.

This is the exact type of task for which BackgroundWorker is meant. You should just push this into a background worker, and allow it to run. This provides a simple way to update your progress bar, etc.

没有理由为此创建自己的线程.通过BackgroundWorker进行的ThreadPool可以很好地工作.

There is no reason to make your own thread for this. The ThreadPool via BackgroundWorker will work perfectly well.

这篇关于后台工作进程或线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆