Esempio n. 1
0
        /// <summary>
        /// Post Progress message for display at next timer tick
        /// </summary>
        /// <param name="caption"></param>
        /// <param name="title"></param>
        /// <param name="allowCancel"></param>
        /// <param name="cancellingMessage"></param>

        public static void Show(
            string caption,
            string title,
            bool allowCancel,
            string cancellingMessage)
        {
            VerifyFormExistence();

            PendingCaption           = caption;
            PendingTitle             = title;
            PendingAllowCancel       = allowCancel;
            PendingCancellingMessage = cancellingMessage;
            PendingShow = true;
            PendingHide = false;
            //if (Instance != null) Instance.ProgressTimer.Enabled = true;

            PerShowCancelRequestedFlag = false;

            if (Debug)
            {
                ClientLog.Message("Progress - Posting Show: " + caption);
            }
            //if (Lex.Contains(caption, "Retrieving data")) caption = caption; // debug

            if (SS.I.LocalServiceMode)             // if local service mode try to show message now since timer ticks may not be processed if in CPU intensive task
            {
                //while (PendingShow)
                {
                    Thread.Sleep(10);
                    UIMisc.DoEvents();

                    string stackTrace = new System.Diagnostics.StackTrace(true).ToString();
                    if (Lex.Contains(stackTrace, "_tick"))                     // if in a timer tick process immediately
                    {
                        Instance.ProgressTimer_Tick(null, null);
                    }
                }
            }

            return;
        }
Esempio n. 2
0
        /// <summary>
        /// When timer ticks perform any pending operations
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void ProgressTimer_Tick(object sender, System.EventArgs e)
        {
            //SystemUtil.Beep(); // debug

            lock (InstanceLock)
            {
                try
                {
                    if (PendingShow)                     // show new progress information
                    {
                        //if (Lex.Contains(PendingCaption, "retrieving")) PendingCaption = PendingCaption; // debug

                        if (Debug)
                        {
                            ClientLog.Message("Progress - Show: " + PendingCaption);
                        }
                        ShowInstance(PendingCaption, PendingTitle, PendingAllowCancel, PendingCancellingMessage);
                        PendingCaption = PendingTitle = PendingCancellingMessage = "";
                        PendingShow    = PendingAllowCancel = false;
                    }

                    else if (PendingHide)                     // hide the progress form
                    {
                        if (Debug)
                        {
                            ClientLog.Message("Progress - Hide");
                        }
                        HideInstance();
                        Size        = OriginalFormSize;                  // restore size to original
                        PendingHide = false;
                        if (!PendingShow)
                        {
                            Owner                 = null;
                            Parent                = null;
                            Location              = new Point(-4096, -4096); // move off screen
                            Discarded             = true;
                            Instance              = null;                    // if no new show pending then don't use this instance again
                            ProgressTimer.Enabled = false;

                            //SessionManager.ActivateShell(); // really needed, this can hide a popup window that has just been shown

                            if (Debug)
                            {
                                ClientLog.Message("Progress - Discarding instance: " + Id + ", Caption: " + Caption.Text);
                            }
                        }
                        return;
                    }

                    if (!Visible)
                    {
                        return;
                    }

                    //if (ProgressBar.Value >= ProgressBar.Maximum)
                    //  ProgressBar.Value = ProgressBar.Minimum;
                    //else ProgressBar.Value++;

                    if (Caption.Text.Contains(".:.."))                     // continue with timer?
                    {
                        Caption.Text = Caption.Text.Replace(".:..", LastTimeText);
                    }

                    if (!String.IsNullOrEmpty(LastTimeText) && Caption.Text.Contains(LastTimeText))
                    {                     // update time display
                        TimeSpan ts       = DateTime.Now.Subtract(StartTime);
                        string   timeText = String.Format("{0}:{1,2:00}", ts.Minutes, ts.Seconds);
                        if (timeText != LastTimeText)
                        {
                            Caption.Text = Caption.Text.Replace(LastTimeText, timeText);
                            LastTimeText = timeText;
                            UIMisc.DoEvents();
                        }
                    }

                    else if (Caption.Text.Contains("0:00"))
                    {                     // start new time display
                        StartTime    = DateTime.Now;
                        LastTimeText = "0:00";
                    }

                    else
                    {
                        LastTimeText = "";
                    }
                }
                catch (Exception ex)
                { ClientLog.Message("ProgressTimer_Tick exception: " + DebugLog.FormatExceptionMessage(ex)); }
            }
        }