Example #1
0
        private async void mCurrentMailbox_MessageDelivery(object sender, cMessageDeliveryEventArgs e)
        {
            // cautions;
            //  the event could be for the previously selected mailbox
            //  this could arrive during the query
            //   therefore some of the messages could be on the grid already
            //  we could be processing one of these when the next one arrives

            if (e.MessageHandles[0].MessageCache != mCurrentMessageCache)
            {
                return;
            }
            if (mFilter != null)
            {
                return;
            }

            var lBindingSource = dgvMessages.DataSource as BindingSource;

            if (lBindingSource == null)
            {
                return;
            }

            frmProgress     lProgress = null;
            List <cMessage> lMessages;

            try
            {
                if (mProgressBar)
                {
                    lProgress = new frmProgress("loading new messages", e.MessageHandles.Count);
                    lProgress.ShowAndFocus(this);
                    var lConfiguration = new cCacheItemFetchConfiguration(lProgress.CancellationToken, lProgress.Increment);
                    ZMessagesLoadingAdd(lProgress); // so it can be cancelled from code
                    lMessages = await mCurrentMailbox.MessagesAsync(e.MessageHandles, null, lConfiguration);
                }
                else
                {
                    lMessages = await mCurrentMailbox.MessagesAsync(e.MessageHandles);
                }
            }
            catch (OperationCanceledException) { return; }
            catch (Exception ex)
            {
                if (!IsDisposed)
                {
                    MessageBox.Show(this, $"a problem occurred: {ex}");
                }
                return;
            }
            finally
            {
                if (lProgress != null)
                {
                    lProgress.Complete();
                }
            }

            // check that while getting the messages we haven't been closed or the mailbox changed
            if (IsDisposed || e.MessageHandles[0].MessageCache != mCurrentMessageCache)
            {
                return;
            }

            // load the grid with data
            ZAddMessagesToGrid(lMessages);
        }
Example #2
0
 private void ZSubscribedMailboxMessageDelivery(object sender, cMessageDeliveryEventArgs e) => ZSubscribedMailboxDisplay();