Beispiel #1
0
 private static void DisposePorts(ReservedPort[] ports)
 {
     foreach (var port in ports)
     {
         try
         {
             port?.Dispose();
         }
         catch (Exception)
         {
             // not much can be done about this
         }
     }
 }
Beispiel #2
0
        public static ReservedPorts Reserve(int count)
        {
            // reserve all of the ports
            var ports = new ReservedPort[count];
            try
            {
                for (int i = 0; i < count; i++)
                {
                    ports[i] = ReservedPort.Reserve();
                }
            }
            catch
            {
                DisposePorts(ports);
                throw;
            }

            return new ReservedPorts(ports);
        }
Beispiel #3
0
        public static ReservedPorts Reserve(int count)
        {
            // reserve all of the ports
            var ports = new ReservedPort[count];

            try
            {
                for (int i = 0; i < count; i++)
                {
                    ports[i] = ReservedPort.Reserve();
                }
            }
            catch
            {
                DisposePorts(ports);
                throw;
            }

            return(new ReservedPorts(ports));
        }
Beispiel #4
0
        public static ReservedPorts Reserve(int count)
        {
            // reserve all of the ports
            var ports = new ReservedPort[count];

            try
            {
                for (int i = 0; i < count; i++)
                {
                    var port = ReservedPort.Reserve();
                    ports[i] = port ?? throw new InvalidOperationException("Could not reserve a port.");
                }
            }
            catch
            {
                DisposePorts(ports);
                throw;
            }

            return(new ReservedPorts(ports));
        }
Beispiel #5
0
 public ReservedPorts(ReservedPort[] ports)
 {
     _ports = ports;
     _disposed = false;
 }