private void StartBinding() { StringBuilder builder = new StringBuilder(); lock (collectedQrCodes) { while (startedBinding) { int count = collectedQrCodes.Count; while (count != 0) { //I can actually get the t selected product name,and distributor id Console.Write(collectedQrCodes[count - 1]); string scannedResult = collectedQrCodes[count - 1]; scannedResult = scannedResult.Replace("\r\n", "").Replace("\r", "").Replace("\n", ""); bindingService.BindProductWithDistributor(scannedResult, selectedProduct, selectedDistributor); collectedQrCodes.RemoveAt(count - 1); count = collectedQrCodes.Count; BindedCount = BindedCount + 1; } Monitor.Wait(collectedQrCodes); } Console.WriteLine("Thread Id: {0} out of current task", Thread.CurrentThread.ManagedThreadId); } }