Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MultiThread Programing

MultiThread Programing

Scheduled Pinned Locked Moved C#
questioncsharpjavadelphicareer
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LincolnGuimaraes
    wrote on last edited by
    #1

    I have to create a multithread program. It must control a pool of thread. How do I do this in C#? The idea is: Reading a properties file, the program will know what kind of thead It will start. Each thread will take care about one subject. Each thread will receive a parameter indicating how many thread will have in its pool. The MainThread will control the pool of thread, when it needs to process some UDP message will request a free thread in the pool. Will pass all of the information (data) to the thread and order to run. When the thread finishs its job will be in suspend mode waiting for next job. I had develop this kind of program in Delphi and in Java with success! But in C# I did not find any way to do this. Thanks. +------+ +----------+ | | |Thread-UDP|-------> +------+ | .EXE |-----> |LISTENER | | T2 | | | +----+-----+ +------+ +------+ | \ | \ \/ \ +-------+ +--------+ | T1 | | T3 + +-------+ +--------+

    Mircea PuiuM Y G J 5 Replies Last reply
    0
    • L LincolnGuimaraes

      I have to create a multithread program. It must control a pool of thread. How do I do this in C#? The idea is: Reading a properties file, the program will know what kind of thead It will start. Each thread will take care about one subject. Each thread will receive a parameter indicating how many thread will have in its pool. The MainThread will control the pool of thread, when it needs to process some UDP message will request a free thread in the pool. Will pass all of the information (data) to the thread and order to run. When the thread finishs its job will be in suspend mode waiting for next job. I had develop this kind of program in Delphi and in Java with success! But in C# I did not find any way to do this. Thanks. +------+ +----------+ | | |Thread-UDP|-------> +------+ | .EXE |-----> |LISTENER | | T2 | | | +----+-----+ +------+ +------+ | \ | \ \/ \ +-------+ +--------+ | T1 | | T3 + +-------+ +--------+

      Mircea PuiuM Offline
      Mircea PuiuM Offline
      Mircea Puiu
      wrote on last edited by
      #2

      There are a lot of tutorials on the topic. You could start very well here[^].

      SkyWalker

      1 Reply Last reply
      0
      • L LincolnGuimaraes

        I have to create a multithread program. It must control a pool of thread. How do I do this in C#? The idea is: Reading a properties file, the program will know what kind of thead It will start. Each thread will take care about one subject. Each thread will receive a parameter indicating how many thread will have in its pool. The MainThread will control the pool of thread, when it needs to process some UDP message will request a free thread in the pool. Will pass all of the information (data) to the thread and order to run. When the thread finishs its job will be in suspend mode waiting for next job. I had develop this kind of program in Delphi and in Java with success! But in C# I did not find any way to do this. Thanks. +------+ +----------+ | | |Thread-UDP|-------> +------+ | .EXE |-----> |LISTENER | | T2 | | | +----+-----+ +------+ +------+ | \ | \ \/ \ +-------+ +--------+ | T1 | | T3 + +-------+ +--------+

        Y Offline
        Y Offline
        Yosh_
        wrote on last edited by
        #3

        This [^] might help. Google it up, there's a million more!

        He who goes for revenge must first dig two graves.

        1 Reply Last reply
        0
        • L LincolnGuimaraes

          I have to create a multithread program. It must control a pool of thread. How do I do this in C#? The idea is: Reading a properties file, the program will know what kind of thead It will start. Each thread will take care about one subject. Each thread will receive a parameter indicating how many thread will have in its pool. The MainThread will control the pool of thread, when it needs to process some UDP message will request a free thread in the pool. Will pass all of the information (data) to the thread and order to run. When the thread finishs its job will be in suspend mode waiting for next job. I had develop this kind of program in Delphi and in Java with success! But in C# I did not find any way to do this. Thanks. +------+ +----------+ | | |Thread-UDP|-------> +------+ | .EXE |-----> |LISTENER | | T2 | | | +----+-----+ +------+ +------+ | \ | \ \/ \ +-------+ +--------+ | T1 | | T3 + +-------+ +--------+

          Y Offline
          Y Offline
          Yosh_
          wrote on last edited by
          #4

          This [^] might help. Or, this[^] Google it up, there's a million more!

          He who goes for revenge must first dig two graves.

          1 Reply Last reply
          0
          • L LincolnGuimaraes

            I have to create a multithread program. It must control a pool of thread. How do I do this in C#? The idea is: Reading a properties file, the program will know what kind of thead It will start. Each thread will take care about one subject. Each thread will receive a parameter indicating how many thread will have in its pool. The MainThread will control the pool of thread, when it needs to process some UDP message will request a free thread in the pool. Will pass all of the information (data) to the thread and order to run. When the thread finishs its job will be in suspend mode waiting for next job. I had develop this kind of program in Delphi and in Java with success! But in C# I did not find any way to do this. Thanks. +------+ +----------+ | | |Thread-UDP|-------> +------+ | .EXE |-----> |LISTENER | | T2 | | | +----+-----+ +------+ +------+ | \ | \ \/ \ +-------+ +--------+ | T1 | | T3 + +-------+ +--------+

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            A while back I wrote a class named SynchronisedQueue[^] for parallel processing of Mandelbrot graphics. The main thread could use it to send the jobs to the threads by simply adding it to the queue. The threads would periodically try to get something from the queue while they are idle. The class for a thread could be something like:

            public class WorkerThread {

            public volatile bool Contine;
            private SynchronisedQueue<Job> _jobs;

            public WorkerThread(SynchronisedQueue<Job> jobs) {
            Contine = true;
            _jobs = jobs;
            }

            public void Run() {
            while (Continue) {
            Job job;
            if (jobs.TryDequeue(out job)) {
            // handle the job
            } else {
            Thread.Sleep(100);
            }
            }
            }

            }

            The main thread creates a queue, then creates the objects for the worker threads and sends the queue along to the constructor. If you need to send a result back from the worker thread to the main thread, you add another queue for the results. When the thread is done it just adds a result to the queue, and you have a timer in the main thread to look for results in the queue. The code for dispatching the jobs gets really simple. There is no requesting of threads and handling the situation of waiting for a free thread, just throw the jobs in the queue, and the first thread that gets free grabs it. :)

            Despite everything, the person most likely to be fooling you next is yourself.

            1 Reply Last reply
            0
            • L LincolnGuimaraes

              I have to create a multithread program. It must control a pool of thread. How do I do this in C#? The idea is: Reading a properties file, the program will know what kind of thead It will start. Each thread will take care about one subject. Each thread will receive a parameter indicating how many thread will have in its pool. The MainThread will control the pool of thread, when it needs to process some UDP message will request a free thread in the pool. Will pass all of the information (data) to the thread and order to run. When the thread finishs its job will be in suspend mode waiting for next job. I had develop this kind of program in Delphi and in Java with success! But in C# I did not find any way to do this. Thanks. +------+ +----------+ | | |Thread-UDP|-------> +------+ | .EXE |-----> |LISTENER | | T2 | | | +----+-----+ +------+ +------+ | \ | \ \/ \ +-------+ +--------+ | T1 | | T3 + +-------+ +--------+

              J Offline
              J Offline
              Joe Woodbury
              wrote on last edited by
              #6

              Programming the Thread Pool in the .NET Framework[^]

              Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups