Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2008
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating threads in C#

    Can someone please break down a simple statement for a relative newbie?

    Code:
    Thread firstThread = new Thread (new ThreadStart (Method1));
    In other words, what is happening at each stage here:

    Code:
    new ThreadStart (Method1)
    Code:
    new Thread (new ThreadStart (Method1))
    Code:
    Thread firstThread = new Thread (new ThreadStart (Method1));
    Thanks for any help you can give.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Code:
    new ThreadStart (Method1)
    ThreadStart is a delegate. Method1 is a function that matches the ThreadStart delegate. Method1 is going to be the entry point (aka the starting point) for the new thread.

    Code:
    new Thread (new ThreadStart (Method1))
    The thread object is being created.

    Code:
    Thread firstThread = new Thread (new ThreadStart (Method1));
    The created thread object is being assigned to firstThread.

    Depending on what you are wanting to do with threads, the BackgroundWorker class which I *think* is in the System.ComponentModel namespace makes it easier to have background worker threads separate from your main program flow.
    OracleGuy

  • #3
    New Coder
    Join Date
    Jul 2009
    Location
    Atlanta, GA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #4
    Regular Coder
    Join Date
    Nov 2008
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts
    scottk:

    >This is a crosspost of http://www.daniweb.com/forums/thread204868.html

    Yes, it is. So what?

    Posting to forums at different websites is not the same as posting to more than one forum at a single website. The idea behind not cross-posting to multiple forums at a single website is to ensure that posts are directed appropriately. Posting to forums with similar topics at different websites is in no way directing posts inappropriately.

    The purpose of posting questions at more than one website is to maximize the chance of getting answers, of course! And why not? Any given question is usually answered at only a minority of forums. But by posting my questions to forums at multiple websites, several different people have responded to each and every one of my questions. They've each been helpful and brought something to the discussion that others at other websites had not thought of. So what does it matter if such helpful people are distributed over several websites?


  •  

    Posting Permissions

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