public AccountWrapperForThreading(Account i_Account, int i_MaxAmount) { MaxAmount = i_MaxAmount; TheAccount = i_Account; }
public static void Main() { Thread[] threads = new Thread[4]; Account account = new Account(1000); for(int i = 0 ; i < 4 ; ++i) { AccountWrapperForThreading wrapper = new AccountWrapperForThreading(account, (i+1)*30); wrapper.Finished += new EventHandler(wrapper_Finished); /// Creating a thread that holds a reference to the DoTransactions method threads[i] = new Thread(new ThreadStart(wrapper.DoTransactions)); /// naming the thread so we can identify it when it finishes threads[i].Name = "Thread 0" + i; } foreach (Thread thread in threads) { /// executing the tread /// and passing a delegate to the thread_Finished method /// as the parameter thread.Start(); } Console.ReadKey(); }