예제 #1
0
        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);
            }
        }
예제 #2
0
        private async void BtnUnblockingByAsync2_Click(object sender, EventArgs e)
        {
            var bindingList = new BindingList <CustomerReportItem>();

            customerReportItemBindingSource.DataSource = bindingList;

            await Task.Run(async() =>
            {
                for (var i = 0; i < 30; i++)
                {
                    // Doesn't work: Crashes.
                    // await CustomerReportItem.AddCustomerReportToBindingListAsync(bindingList, i);
                    await asyncControl.InvokeAsync(() => CustomerReportItem.AddCustomerReportToBindingListAsync(bindingList, i));
                }
            });
        }
예제 #3
0
        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);
                    });
                }
            });
        }