Может кто-нибудь помочь мне с нарезанием резьбы?
У меня есть какой-то код, который я не могу запустить. Я представил кодекс на рассмотрение. Заранее благодарю вас за вашу помощь.
<pre> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace IT481_Unit6_Assignment { using System; using System.Threading; public class DressingRoom { private static Semaphore available; public static void Main() { int ClothingsItemsGenerator = 0; int GenNumberOfItems; int max = 10; int min = 1; //Create a random number of available rooms //create random class for number generation Random rndNum = new Random(); int dressing = rndNum.Next(1, 20); //Program is only displaying this random number Console.WriteLine("The average number of items being tried on is " + dressing); Console.ReadKey(); //create random number for customers Random rndCust = new Random(); int cust = rndNum.Next(30, 50); Console.WriteLine("The average number of customers requesting rooms is " + cust); Console.ReadKey(); Random rndSleep = new Random(); int SleepTimer = rndSleep.Next(60000, 180000); Console.WriteLine("The average time spent in a dressing room is " + SleepTimer + "milliseconds."); Console.ReadKey(); available = new Semaphore(min, max); for (int i = 1; i <= cust; i++) { if (ClothingsItemsGenerator == dressing) { GenNumberOfItems = ClothingsItemsGenerator.Next((max - min) + 1) + min; Console.WriteLine(ClothingsItemsGenerator + " itmes."); NewMethod(GenNumberOfItems); } Console.WriteLine("Checking for available rooms..."); Console.WriteLine("Customer {0} enters the dressing room", i); Console.WriteLine("Customer {0} leaves the dressing room", i); available.WaitOne(); available.Release(); Console.WriteLine("There are now {0} dressing rooms left.", dressing, available.Release()); Console.Read(); Thread t = new Thread(new ParameterizedThreadStart(DressingRoom)); //Start letting customers use dressing rooms. DressingRoom.Start(i); } } private static void NewMethod(int GenNumberOfItems) { Customer cust = new Customer(GenNumberOfItems, CustNumCount); } private Semaphore avaliable; private static int ClothingsItmes = 0; private static readonly Random ClothingItemsGenerator = new Random(); private static int sleepTime; private static int GenNumbersOfItems; private static readonly Random sleepTimeGenerator = new Random(); private static int max = 20; private static int min = 1; private static int sleepMin = 60000; private static int sleepMax = 180000; private static int CustNumCount; public DressingRoom(int MAX_ROOMS_AVAILABLE, int CustNum, int NumberOfItems) { available = new Semaphore(CustNumCount, MAX_ROOMS_AVAILABLE); Console.WriteLine("Did it get here?"); Console.WriteLine(CustNum); try { Console.WriteLine(CustNum); RequestRoom(NumberOfItems, CustNum); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.WriteLine(e.StackTrace); } } public virtual void RequestRoom(int NumberOfItems, int CustNum) { Console.WriteLine("Is a customer requesting a room?"); Console.WriteLine(CustNum); for (int i = 0; i < CustNum; i ++) { Console.WriteLine("How many itmes does the customer have"); if (NumberOfItems == 0) { GenNumbersOfItems = ClothingItemsGenerator.Next((max - min) + 1) + min; Console.WriteLine(NumberOfItems + " itmes."); Customer cust = new Customer(this, GenNumbersOfItems, CustNum); } } } public class Customer { private DressingRoom dressingRoom; private int genNumberOfItmes; private int custNum; private object custNum1; public Customer(int NumberOfItems) { int max = 20; int min = 1; Console.WriteLine("Does it make instantiate customer?"); Console.WriteLine("Here is the total number items " + NumberOfItems); if (NumberOfItems ==0) { NumberOfItems = ClothingItemsGenerator.Next(max - min + 1) + min; Console.WriteLine(NumberOfItems); } else { Console.WriteLine(NumberOfItems); } } public Customer(int NumberOfItmes, object custNum1) : this(NumberOfItmes) { this.custNum1 = custNum1; } public Customer(DressingRoom dressingroom, int genNumberOfItems, int custNum) { this.dressingRoom = dressingRoom; this.genNumberOfItmes = genNumberOfItmes; this.custNum = custNum; } } public virtual void Scenario() { try { Console.WriteLine("There are a total number of " + CustNumCount + " customer"); available.WaitOne(); } catch (ThreadInterruptedException) { Console.WriteLine("received thread interuption exception"); } Console.WriteLine("Customer " + CustNumCount + " starts to use the room"); Console.WriteLine(GenNumbersOfItems + " here is the number of itmes"); for (int i = 0; i < GenNumbersOfItems; i++) { try { sleepTime = sleepTimeGenerator.Next((sleepMax - sleepMin) + 1) + sleepMin; Console.WriteLine("{0} goint to sleeo for {1:D} milliseconds. \n", sleepTime); Thread.Sleep(sleepTime); } catch (ThreadInterruptedException) { Console.WriteLine("Received thread interupted exception"); } Console.WriteLine("Customer " + CustNumCount + " left the room"); available.Release(); } } } }
Что я уже пробовал:
Я попытался изменить код вокруг, чтобы заставить его работать.