private void ModifyMailboxApproval(ApprovalStatus approvalStatus) { IList <DataGridViewRow> checkedRows = (from DataGridViewRow row in mailboxDataGridView.Rows where Convert.ToBoolean(row.Cells[MailboxRowCheckBox.Name].Value) == true select row).ToList(); WorkAsync(new WorkAsyncInfo { Message = "Modifying mailboxes", IsCancelable = true, AsyncArgument = checkedRows, Work = (worker, args) => { var rows = args.Argument as IList <DataGridViewRow>; for (var i = 0; i < rows.Count(); i++) { DataGridViewRow row = rows[i]; string mailboxName = row.Cells[2].Value as string; worker.ReportProgress(-1, $"Modifying mailbox {mailboxName} to {approvalStatus}"); if (row.Cells[1].Value is Guid mailboxId) { MailboxDao mailboxDao = new MailboxDao(Service); Exception approvalException = mailboxDao.SetApproval( mailboxId, approvalStatus); if (approvalException != null) { LogError($"Failed to approve mailbox"); LogError(approvalException.Message); LogError(approvalException.StackTrace); } } } }, ProgressChanged = e => { SetWorkingMessage(e.UserState.ToString()); }, PostWorkCallBack = (args) => { if (args.Error != null) { MessageBox.Show( args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } TsbLoadMailboxes.Visible = false; TsbUpdateMailboxes.Visible = false; TsbSelectAll.Visible = false; TsbSelectNone.Visible = false; mailboxDataGridView.DataSource = null; TscbActionType.SelectedIndex = 0; MessageBox.Show("Complete"); } });
private void GetMailboxes( Action <RunWorkerCompletedEventArgs> postWorkCallBack, params ApprovalStatus[] approvalStatuses) { MailboxDao mailboxDao = new MailboxDao(Service); bool parsed = int.TryParse(TstbPageSize.Text, out int pageSize); if (parsed) { mailboxDao.PageSize = pageSize; } WorkAsync(new WorkAsyncInfo { Message = "Getting mailboxes", Work = (worker, args) => { args.Result = mailboxDao.Get(worker, approvalStatuses); }, ProgressChanged = (e) => { SetWorkingMessage(e.UserState.ToString()); }, PostWorkCallBack = postWorkCallBack }); }