Results 1 to 2 of 2

Thread: Threading Code.

  1. #1
    Junior Member
    Join Date
    Nov 2014
    Repulic Of Korea

    Threading Code.


    I declared on class
    " private Thread t1; "

    this.t1 = new Thread(new ThreadStart(Check()));

    public void OnPluginEnable()

    Nothing work.....
    but ,

    Not declare On class And..

    public void OnPluginEnable()
    Thread t1 = new Thread(new ThreadStart(Check()));

    is work.. why it is??

    I want to make Thread for use any method.

    Can i make it?
    Last edited by ajzksh7; 05-02-2016 at 11:07.

  2. #2
    Like this

    Thread t1;
    t1 = new Thread(Check);

    You should only use this method for long duration threads like worker threads that are constantly functioning in the background of your plugin. You can create more threads than your CPU can handle this way. You also have to release the thread when you are done with it so you have to keep track of how many you have started.


    You can do this for short duration threads that aren't looping
    ThreadPool.QueueUserWorkItem((state) => { Check(); });

    Threadpool is designed for short duration threads and only starts as many as there are available. If too many threads are generated the incoming work is put into a queue until a thread is free to run it. This is the preferred method for short duration threads and is easier to use. Plus you can use the syntax I show with the lambda expression to send any function into the thread including functions that take arguments
    Last edited by s1ngular1ty; 03-04-2016 at 19:05.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts