以下是我正在研究的类的一个简化版本(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)