public void Start(int counter, int msgCount) { int i = counter; while (i < msgCount) { Console.WriteLine("Thread ID: " + Thread.CurrentThread.ManagedThreadId); //Add to Cache list var ciEvents = CICache.GetOrAdd("CIEvents"); if (ciEvents != null) { // do validation of the message. ciEvents.Add(i.ToString()); Console.WriteLine(ciEvents.Count + " added to the cache list"); //if Cache list > 10 if (ciEvents.Count > 10) { //post the message to db and EH CICache.cache.Remove("CIEvents"); if (CICache.cache.Get <List <string> >("CIEvents") == null) { Console.WriteLine("CI Events key removed..."); } } } i++; Thread.Sleep(300); } }
static void Main(string[] args) { Console.WriteLine("CI receiver Batch Insert with Caching..."); CICache.GetOrAdd("CIEvents"); CIReceiver receiver = new CIReceiver(); CIReceiver receiver2 = new CIReceiver(); Task.Run(() => receiver2.Start(1, 50)); receiver.Start(51, 100); Console.WriteLine("End of Program. Press any key to continue..."); Console.ReadLine(); }