C# Running code in a new thread

Below are various example snippets on starting code in a new thread easily. As well as updating the UI from your new thread.

These are the most basic examples, for more information take a look at the Threading Tutorial on the MSDN website: https://msdn.microsoft.com/en-us/library/aa645740(v=vs.71).aspx

Start a new Thread and run your code.

using System.Threading;
new Thread(() => 
{
    Thread.CurrentThread.IsBackground = true; 
    Console.WriteLine("Hello, world"); 
}).Start();

Start a new thread and call a method

Thread t = new Thread(new ThreadStart(YourMethod));
t.Name = "Your new thread.";
t.Start();    

static void YourMethod() {
   //Your code runs here.
}

Using Tasks to start a new thread.

using System.Threading.Tasks;
Task.Factory.StartNew(() => {Console.WriteLine("Your new thread."); });

.NET4 and Above. Update UI Control from Thread

control.Invoke((MethodInvoker) (() => control.Text = "new text"));