Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 9 years ago

How do make my program runs several activities without multithreading?

3 Answers

Relevance
  • oops
    Lv 6
    9 years ago
    Favorite 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.

  • Pyros
    Lv 5
    9 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)

    );

  • 9 years ago

    You can't. That's like trying to drink from an empty glass.

Still have questions? Get your answers by asking now.