-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main_Program.cs
62 lines (49 loc) · 2.19 KB
/
Main_Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Threading;
namespace Flight_Ticket_Booking
{
// Main program that creates airline and travel agent threads
class Main_Program
{
const int NUMBER_OF_AIRLINES = 3;
const int NUMBER_OF_AGENTS = 5;
static public MultiCellBuffer multiBuffer;
static public TravelAgency[] agencyArray;
static public Thread[] agencyThreads;
static void Main(string[] args)
{
multiBuffer = new MultiCellBuffer();
// Creates and starts the Airline threads
Airline[] airlineArray = new Airline[NUMBER_OF_AIRLINES];
Thread[] airlineThreads = new Thread[NUMBER_OF_AIRLINES];
for (int i = 0; i < NUMBER_OF_AIRLINES; i++)
{
airlineArray[i] = new Airline(i);
airlineThreads[i] = new Thread(new ThreadStart(airlineArray[i].airlineFunction));
airlineThreads[i].Name = (i).ToString();
airlineThreads[i].Start();
Thread.Sleep(050);
}
Console.WriteLine("Airlines Initialized");
// Creates and starts agency threads
agencyArray = new TravelAgency[NUMBER_OF_AGENTS];
agencyThreads = new Thread[NUMBER_OF_AGENTS];
for (int i = 0; i < NUMBER_OF_AGENTS; i++)
{
agencyArray[i] = new TravelAgency();
Airline.priceCut += new priceCutEvent(agencyArray[i].ticketOnSale);
agencyThreads[i] = new Thread(new ThreadStart(agencyArray[i].agencyFunction));
agencyThreads[i].Name = (i).ToString();
agencyThreads[i].Start();
}
Console.WriteLine("Agencies Initialized");
// Wait for airlines threads to complete then alert travel agency threads to quit
for (int i = 0; i < airlineThreads.Length; i++)
{
airlineThreads[i].Join();
}
TravelAgency.airlines_done = true;
Console.WriteLine("...................................main thread complete");
}
}
}