public static void WorkerFilaDisciplina() { var f = new FilaDisciplinas(); Tuple <string, string, ConcurrentBag <Disciplina>, string> msg; ClienteWeb wc = new ClienteWeb(); wc.Encoding = Encoding.UTF8; while ((msg = f.Get()) != null) { // f.Put(Tuple.Create(urlCampus, url.Current.Value, discs, nome.Current.Value)); var dep = new Disciplina(); dep.Nome = msg.Item4; var discs = msg.Item3; var urlCampus = msg.Item1; Console.WriteLine("\tLendo disc. " + dep.Nome); dep.Turmas = LerTurmas(urlCampus, msg.Item2, wc); Console.WriteLine("depth: " + CodeMQManager.GetQueueDepth(typeof(FilaDisciplinas))); discs.Add(dep); } f.Put(null); }
public static void PrintQueueDepths() { lock (typeof(Utilities)) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; var left = Console.CursorLeft; var top = Console.CursorTop; var depths = CodeMQManager.GetQueueDepths(); List <string> texts = new List <string>(); texts.Add(" "); texts.Add(" Queue depths "); texts.Add(" "); texts.AddRange(depths.Select(n => " " + n.Key.Name + ": " + n.Value + " ")); texts.Add(" "); int newLeft = Console.WindowWidth - texts.Max(n => n.Length); int wt = Console.WindowTop; Console.CursorTop = wt; Console.CursorLeft = newLeft; for (int i = 0; i < texts.Count; i++) { Console.Write(texts[i].PadLeft(texts.Max(n => n.Length))); wt += 1; Console.CursorTop = wt; Console.CursorLeft = newLeft; } Console.BackgroundColor = ConsoleColor.Black; Console.CursorTop = top; Console.CursorLeft = left; } }
static void Main(string[] args) { CodeMQManager.LoadQueue(typeof(Queues.NumberToTextQueue)); CodeMQManager.LoadQueue(typeof(Queues.ToUpperQueue)); var t = new Thread(() => NumberToTextWorker()); var t1 = new Thread(() => ToUpperWorker()); var t2 = new Thread(() => QueueDepthsWorker()); t.Start(); t1.Start(); t2.Start(); var qnum = new Queues.NumberToTextQueue(); var qup = new Queues.ToUpperQueue(); qnum.Put(1); Utilities.Write(ConsoleColor.Yellow, "Produced " + 1); qup.Put("abc"); Utilities.Write(ConsoleColor.Yellow, "Produced abc"); qnum.Put(2); Utilities.Write(ConsoleColor.Yellow, "Produced " + 2); qnum.Put(3); Utilities.Write(ConsoleColor.Yellow, "Produced " + 3); qnum.Put(4); Utilities.Write(ConsoleColor.Yellow, "Produced " + 4); qnum.Put(5); Utilities.Write(ConsoleColor.Yellow, "Produced " + 5); qnum.Put(10); Utilities.Write(ConsoleColor.Yellow, "Produced " + 10); qup.Put("test"); Utilities.Write(ConsoleColor.Yellow, "Produced test"); qnum.Put(-1); Utilities.Write(ConsoleColor.Yellow, "Produced end request"); t.Join(); t1.Join(); Utilities.Write(ConsoleColor.Yellow, "Execution ended, next example will start in 3 sec."); Thread.Sleep(3000); CodeMQManager.LoadQueue(typeof(LogQueue)); CodeMQManager.LoadQueue(typeof(TreeWorkerResultQueue)); CodeMQManager.LoadQueue(typeof(TreeWorkerRequestQueue)); // build a tree. var node = new TreeNode(1) { new TreeNode(2) { new TreeNode(4) { new TreeNode(8), new TreeNode(9) } }, new TreeNode(3) { new TreeNode(6), new TreeNode(5), new TreeNode(7) } }; var tC = new Thread(() => ControlWorker()); var tw1 = new Thread(() => TreeWorker()); var tw2 = new Thread(() => TreeWorker()); var tw3 = new Thread(() => TreeWorker()); var tw4 = new Thread(() => TreeWorker()); var tw5 = new Thread(() => TreeWorker()); var tw6 = new Thread(() => TreeWorker()); var tw7 = new Thread(() => TreeWorker()); var tw8 = new Thread(() => TreeWorker()); tC.Start(); tw1.Start(); tw2.Start(); tw3.Start(); tw4.Start(); Utilities.Write(ConsoleColor.Gray, "Traversal in progress..."); var w = new TreeWorkerResultQueue(); // request to visit first tree node, to start the chain reaction w.Put(new TreeWorkerResultMessage() { processed = false, result = node }); tC.Join(); tw1.Join(); tw2.Join(); tw3.Join(); tw4.Join(); Utilities.Write(ConsoleColor.Gray, "Traversal ended. Results:"); var l = new LogQueue(); while (CodeMQManager.GetQueueDepth(typeof(LogQueue)) > 0) { Utilities.Write(ConsoleColor.Gray, l.Get()); } Utilities.Write(ConsoleColor.Gray, "Execution ended. ENTER to exit."); t2.Abort(); Console.ReadLine(); }