小编Rhy*_*led的帖子

为什么/如何在没有DoWorkEventArgs的情况下使用BackgroundWorker?

以下是我正在研究的类的一个简化版本(WinForms项目的一部分):

class ReportBuilder {
    private List<Project> projects;
    private List<Invoice> invoices;
    private MyAPI apiObject;

    public ReportBuilder(MyAPI apiAccess, List<Project> selectedProjects){
        this.apiObject = apiAccess;
        this.projects = selectedProjects;
    }

    public void DownloadData(){
        BackgroundWorker workerThread = new BackgroundWorker();
        workerThread.DoWork += (sender, e) => this.retrieveInvoices(this.projects); // yes, the parameter is unnecessary in this case, since the variable is in scope for the method anyway, but I'm doing it for illustrative purposes
        workerThread.RunWorkerCompleted += receiveData;
        workerThread.RunWorkerAsync();
    }

    private void retrieveInvoices(List<Project> filterProjects){
        Notification status;
        if (filterProjects == null){this.invoices …
Run Code Online (Sandbox Code Playgroud)

c# backgroundworker

0
推荐指数
1
解决办法
73
查看次数

标签 统计

backgroundworker ×1

c# ×1