示例#1
0
        public static CursorWait New(Control objControl = null, bool blnAppStarting = false)
        {
            CursorWait objReturn = new CursorWait(objControl, blnAppStarting);

            if (objReturn._objControl.IsNullOrDisposed())
            {
                if (Interlocked.Increment(ref _intApplicationWaitCursors) == 1)
                {
                    Application.UseWaitCursor = true;
                }
                return(objReturn);
            }
            objReturn._objTimer.Start();
            Log.Trace("CursorWait for Control \"" + objControl + "\" started with Guid \"" + objReturn._guidInstance + "\".");

            if (objReturn._objControl != null)
            {
                if (objReturn._blnAppStartingCursor)
                {
                    s_DicApplicationStartingControls.AddOrUpdate(objReturn._objControl, 1,
                                                                 (x, y) => Interlocked.Increment(ref y));
                    if (!s_DicWaitCursorControls.TryGetValue(objReturn._objControl, out int intExitingWaits) ||
                        intExitingWaits == 0)
                    {
                        objReturn.SetControlCursor(Cursors.AppStarting);
                    }
                }
                else
                {
                    s_DicWaitCursorControls.AddOrUpdate(objReturn._objControl, 1, (x, y) => Interlocked.Increment(ref y));
                    objReturn.SetControlCursor(Cursors.WaitCursor);
                }
            }
            return(objReturn);
        }
示例#2
0
        public static CursorWait New(Control objControl = null, bool blnAppStarting = false)
        {
            CursorWait objReturn = new CursorWait(objControl, blnAppStarting);

            if (objReturn._objControl == null)
            {
                if (Interlocked.Increment(ref _intApplicationWaitCursors) == 1)
                {
                    Application.UseWaitCursor            = true;
                    objReturn._blnDoUnsetCursorOnDispose = true;
                }
                return(objReturn);
            }
            Form frmControl = objReturn._objControl as Form;

            if (frmControl?.DoThreadSafeFunc(x => x.IsMdiChild) != false)
            {
                if (frmControl != null)
                {
                    objReturn._frmControlTopParent = frmControl.DoThreadSafeFunc(x => x.MdiParent);
                }
                else if (objReturn._objControl is UserControl objUserControl)
                {
                    objReturn._frmControlTopParent = objUserControl.DoThreadSafeFunc(x => x.ParentForm);
                }
                else if (objReturn._objControl != null)
                {
                    for (Control objLoop = objReturn._objControl.DoThreadSafeFunc(x => x.Parent); objLoop != null; objLoop = objLoop.DoThreadSafeFunc(x => x.Parent))
                    {
                        if (objLoop is Form objLoopForm)
                        {
                            objReturn._frmControlTopParent = objLoopForm;
                            break;
                        }
                    }
                }
            }

            if (objReturn._objControl != null)
            {
                if (objReturn._blnAppStartingCursor)
                {
                    int intNewValue = s_DicCursorControls.AddOrUpdate(objReturn._objControl, 1, (x, y) => Interlocked.Increment(ref y));
                    objReturn.SetControlCursor(intNewValue < short.MaxValue ? Cursors.AppStarting : Cursors.WaitCursor);
                    objReturn._blnDoUnsetCursorOnDispose = true;
                }
                else
                {
                    s_DicCursorControls.AddOrUpdate(objReturn._objControl, short.MaxValue, (x, y) => Interlocked.Add(ref y, short.MaxValue));
                    objReturn.SetControlCursor(Cursors.WaitCursor);
                    objReturn._blnDoUnsetCursorOnDispose = true;
                }
            }
            return(objReturn);
        }