private void BtnStartBlockingTask_Click(object sender, EventArgs e) { // Simulate getting the Data from a Report engine, and displaying them in the Grid via Binding. var bindingList = new BindingList <CustomerReportItem>(); customerReportItemBindingSource.DataSource = bindingList; for (var i = 0; i < 30; i++) { CustomerReportItem.AddCustomerReportToBindingList(bindingList, i); } }
private async void BtnUnblockingByAsync1_Click(object sender, EventArgs e) { // Simulate getting the Data from a Report engine, and displaying them in the Grid via Binding. var bindingList = new BindingList <CustomerReportItem>(); customerReportItemBindingSource.DataSource = bindingList; await Task.Run(() => { for (var i = 0; i < 30; i++) { // Doesn't work: Cross-Thread Exception. // CustomerReportItem.AddCustomerReportToBindingList(bindingList, i); asyncControl.Invoke((MethodInvoker) delegate { CustomerReportItem.AddCustomerReportToBindingList(bindingList, i); }); } }); }