fguihen Posted April 18, 2005 Posted April 18, 2005 ive never multithreaded an app before. i have a bot class. this bot is supposed to navigate its way through a corridor. the corridor is drawn onto a forum. all the bots are created on the forum, given various parameters, added to an arraylist, and their processing methods are called through a loop. im trying to time the duration of processing for each bot, but the last bot always has the accumulated time for all bots. if i multithread i imagine i could get rid of this. can anyone explain how i might go about this? Quote
Mister E Posted April 18, 2005 Posted April 18, 2005 Create some sort of class that accepts a particular bot. All of the logic that operates on the bot could also be encapsulated in this class as well. Inside the class you will have a timestamp for when the class was instantiated. You will also have a public getter for retrieving the current time invested by that bot. After instantiating a instance of this class, you will start the bot in its own thread: BotMonitor m = new BotMonitor(someBot); Thread t = new Thread(new ThreadStart(m.StartBot)); t.Start(); // use later at some point Console.WriteLine( m.TimeInvested );Keep in mind that if you plan to access any shared resources, such as the bot itself, you will need to make sure the manner in which you do so is thread safe. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.