Exemplo n.º 1
0
            public Starter(GUICommandBase owner, bool resuming, int tryCount, int delay, int interval)
            {
                // argument checks
                if (owner == null)
                {
                    throw new ArgumentNullException(nameof(owner));
                }
                if (tryCount <= 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(tryCount));
                }
                if (delay < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(delay));
                }
                if (interval < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(interval));
                }

                // initialize members
                this.Owner    = owner;
                this.Resuming = resuming;
                this.TryCount = tryCount;
                this.Delaly   = delay;
                this.Interval = interval;

                return;
            }
Exemplo n.º 2
0
            private void TryToStart()
            {
                GUICommandBase owner   = this.Owner;
                int            counter = this.TryCount;
                string         logMessage;

                // try to start proxying
                logMessage = string.Format(Resources.GUICommandBase_Message_TryStarting, this.Delaly);
                owner.LogVerbose(logMessage);
                Thread.Sleep(this.Delaly);
                Debug.Assert(0 < counter);
                do
                {
                    // check whether starting was canceled
                    lock (this.instanceLocker) {
                        if (this.canceled)
                        {
                            break;
                        }
                    }

                    // try to start proxying
                    try {
                        owner.StartProxy(forScheduled: true);
                        break;
                    } catch {
                        // continue;
                    }

                    // prepare the next try
                    --counter;
                    if (counter <= 0)
                    {
                        // fail to resume
                        owner.GiveUpScheduledStarting();
                        owner.LogError(Resources.GUICommandBase_Message_FailToStart);
                        break;
                    }
                    logMessage = string.Format(Resources.GUICommandBase_Message_RetryStarting, this.Interval);
                    owner.LogError(logMessage);
                    Thread.Sleep(this.Interval);
                } while (true);

                return;
            }