Ejemplo n.º 1
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));
        }
Ejemplo n.º 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++)
                {
                    var port = ReservedPort.Reserve();
                    ports[i] = port ?? throw new InvalidOperationException("Could not reserve a port.");
                }
            }
            catch
            {
                DisposePorts(ports);
                throw;
            }

            return(new ReservedPorts(ports));
        }