Threads in C#

Discussion in 'Code Snippets and Tutorials' started by Belaarx, Dec 9, 2008.

  1. Belaarx

    Belaarx Level I

    Joined:
    Sep 23, 2008
    Messages:
    135
    Likes Received:
    16
    Location:
    San Diego
    I have been screwing around in Visual C# recently and have thrown together a USAB. It works fine but the program freezes when it searches. This was also the case in a username grabber that I made in C#

    Could someone explain to me/provide example code on running multiple threads?
     
  2. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    just use this code:
    Code (Text):
    1. Thread t = New Thread(SubYouWantToExecute);
    2. t.IsBackground = True;
    3. t.Start([Optional parameter to pass to the thread]);
    To edit controls properties you can either set the "Control.CheckForIllegalCrossThreadCalls" property to false, or use delegates.
     
  3. Belaarx

    Belaarx Level I

    Joined:
    Sep 23, 2008
    Messages:
    135
    Likes Received:
    16
    Location:
    San Diego
    Are there any namespaces I need to import?
     
  4. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    System.Threading, I think.