private void DoWork() { try { while (!cancelToken.IsCancellationRequested) { Transaction transactionToProcess; transactionToProcess = bank.BankQueue().Dequeue(); if (transactionToProcess != null) { ProcessTransaction(transactionToProcess); } cancelToken.ThrowIfCancellationRequested(); Thread.Sleep(100); } } catch (OperationCanceledException oce) { } finally { uiHelper.AddTellerStoppedMessage(string.Format(" --Teller Stopped {0}", tellerTask.Id)); } }
private void Generate() { try { while (!cancelToken.IsCancellationRequested) { { currentTranAmount++; Customer cust = customerList.GetRandomCustomer(cancelToken); if (cust != null) { Transaction tran = new Transaction(cust, (decimal)rand.Next(1, maxTransAmount), RandomTransactionType()); tran.TransactionGenerator = this; bank.BankQueue().Enqueue(tran); cancelToken.ThrowIfCancellationRequested(); } Thread.Sleep(100); } } } catch (OperationCanceledException) { } finally{ uiHelper.AddTellerStoppedMessage(string.Format("TransactionGenerator {0} Stopped!", task.Id)); //Tried but was unable to serialize current state to include bank, customers, history, etc.. // Worked through a bunch of "not serializable" errors, // and marked the appropriate fields/properties as [NonSerialized]; //but couldn't track them all down. //try //{ // formatter = new SoapFormatter(); // using (stream = new FileStream(SerializedFileName, FileMode.Create)) // { // //Write values to SerializedFileName // formatter.Serialize(stream, bank); // } //} //catch (Exception ex) //{ // MessageBox.Show(string.Format("Error Serializing to {0}. Message = {1}", SerializedFileName, ex.Message)); //} } }
private void Simulate() { bank = new Bank(uiHelper, cancelTokenSource.Token, numberTellers, numberCustomers, bankVaultAmount, maxTransactionAmount, customersGoal, initCustomersAmount); uiHelper.AddListBoxItem("BankSimulator.Simulate Started..."); transactionGenerator = new TransactionGenerator(uiHelper, cancelTokenSource.Token, bank.BankQueue(), bank.Customers(), maxTransactionAmount, timeOutThrottle, bank.Tellers(), bank); }