Trending News
How do make my program runs several activities without multithreading?
3 Answers
- oopsLv 69 years agoFavorite Answer
Design the activities in such a way that they can run in slices, and run them in an infinite loop. In fact, pretty much any program that is designed to interact with users(GUI programs, video games, etc...) runs this way. For example, here's pseudo-code of a video game's main loop:
while(true)
{
GetUserInput();
if (QuitSignalReceived())
break;
UpdateGameObjects();
ShowGraphics();
}
This loop runs hundreds or thousands of times per second, each function is only designed to do fractions of a second worth of work.
- PyrosLv 59 years ago
You can't really... if you're using .net framework then you can use the invoke method of system.threading.parallel class and .net will take care of the grunt work for you. If you want more control then look up a thread pool or a background worker. The invoke trick is done like so:
Parallel.Invoke (
() => method1(arguments),
() => method2(arguments)
);