I have 4 tasks to complete using multithreading concept. and I have 4 Waitress.
How to assign the waitress that are free to handle either one of the task??
-I kept on getting duplicated data (For eg : 4 Thread doing the similar task) -If i used lock, it locks 1 thread to do 4 tasks which is not wat i want
my code:
private void MTDemo() { String threadName = Thread.CurrentThread.Name; while (true) { int numWaitingCustomer = 0; Int32.TryParse(textBox1.Text, out numWaitingCustomer); if (numWaitingCustomer > 0) { String takeOrderString = String.Format("Take order {0},{1}", threadName, numWaitingCustomer); String serveMeal = String.Format("Serve meal {0},{1}",threadName, numWaitingCustomer); String billCustomer = String.Format("Bill Customer {0},{1}", threadName, numWaitingCustomer); String cleanTable = String.Format("Clean Table {0},{1}", threadName, numWaitingCustomer); OutputMessage1(takeOrderString); Thread.Sleep(500); OutputMessage1(serveMeal); Thread.Sleep(500); OutputMessage1(billCustomer); Thread.Sleep(500); OutputMessage1(cleanTable); Thread.Sleep(500); numWaitingCustomer--; SetControlPropertyValue(textBox1, "text", numWaitingCustomer.ToString()); } } }