Exemple #1
0
        public void ProduceWorkItems()
        {
            Random random     = new Random();
            int    upperLimit = random.Next(5, 11);

            for (int i = 0; i <= upperLimit; i++)
            {
                Guid     jobId = Guid.NewGuid();
                WorkTask wt    = new WorkTask(string.Concat("Work with job ID ", jobId), DateTime.UtcNow);
                Console.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId} added work {wt.Description} at {wt.InsertedUtc} to the work queue in iteration {i + 1}.");
                workQueue.AddTask(wt);
                Thread.Sleep(2000);
            }
        }
        public void ProduceWorkItems()
        {
            //while (true)
            //{
            for(int i =0;  i <= 1000000; i++)
            {
                Guid jobID = Guid.NewGuid();
                WorkTask wt = new WorkTask(string.Concat("Work with job ID ", jobID), DateTime.UtcNow);
               // Debug.WriteLine(string.Format("Thread {0} added work {1} at {2} to the work queue.",Thread.CurrentThread.ManagedThreadId, wt.Description, wt.InsertedUtc));
                workQueue.AddTask(wt);
                //Thread.Sleep(500);
            }

            //}
        }
Exemple #3
0
 public void MonitorWorkQueue()
 {
     while (true)
     {
         try
         {
             WorkTask wt = workQueue.Take();
             Console.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId} processing work task {wt.Description}, entered on {wt.InsertedUtc}");
         }
         catch (InvalidOperationException)
         {
             Console.WriteLine($"Work queue on thread {Thread.CurrentThread.ManagedThreadId} has been closed.");
             break;
         }
     }
 }
Exemple #4
0
 public void AddTask(WorkTask workTask)
 {
     workQueue.Add(workTask);
 }
Exemple #5
0
 public void AddTask(WorkTask task)
 {
     workQueue.Add(task);
 }