public static ToStarting ( |
||
status | The status to transition from. | |
return | 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));
}
}
/// <summary> /// Starts local port forwarding. /// </summary> protected override void StartPort() { if (!ForwardedPortStatus.ToStarting(ref _status)) return; try { InternalStart(); } catch (Exception) { _status = ForwardedPortStatus.Stopped; throw; } }