Renci.SshNet.ForwardedPortStatus.ToStarting C# (CSharp) Méthode

ToStarting() public static méthode

Returns a value indicating whether status has been changed to Starting.
While a transition from Started to Starting is not possible, this method will return false for any such attempts. This is related to concurrency.
Cannot transition to .
public static ToStarting ( ForwardedPortStatus &status ) : bool
status ForwardedPortStatus The status to transition from.
Résultat bool
        public static bool ToStarting(ref ForwardedPortStatus status)
        {
            // attemp to transition from Stopped to Starting
            var previousStatus = Interlocked.CompareExchange(ref status, Starting, Stopped);
            if (previousStatus == Starting || previousStatus == Started)
            {
                // port is already Starting or Started, so no transition to Starting is necessary
                return false;
            }

            // we've successfully transitioned from Stopped to Starting
            if (status == Starting)
                return true;

            // there's no valid transition from status to Starting
            throw new InvalidOperationException(string.Format("Forwarded port cannot transition from '{0}' to '{1}'.",
                                                              previousStatus,
                                                              Starting));
        }
    }

Usage Example

        /// <summary>
        /// Starts local port forwarding.
        /// </summary>
        protected override void StartPort()
        {
            if (!ForwardedPortStatus.ToStarting(ref _status))
                return;

            try
            {
                InternalStart();
            }
            catch (Exception)
            {
                _status = ForwardedPortStatus.Stopped;
                throw;
            }
        }
All Usage Examples Of Renci.SshNet.ForwardedPortStatus::ToStarting