Results 1 to 2 of 2

Thread: Threading Code.

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

    Threading Code.

    Hello

    I declared on class
    " private Thread t1; "

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

    public void OnPluginEnable()
    {
    t1.start();
    }

    Nothing work.....
    but ,

    Not declare On class And..

    public void OnPluginEnable()
    {
    Thread t1 = new Thread(new ThreadStart(Check()));
    t1.start();
    }

    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 12:07.

  2. #2
    Like this

    Thread t1;
    t1 = new Thread(Check);
    t1.Start();

    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.

    or

    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 20: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
  •