WPF - Starting a new thread
I have given a simple WPF application that can start a new thread.
System.Threading.Thread is the class you want to use to create a thread. When you instantiate System.Threading.Thread the class you can pass two kinds of delegate.
System.Threading.ThreadStart and System.Threading.ParameterizedThreadStart
Here is the sample code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Threading;
namespace Multi_Threading_Sample
{
public partial class Window1 : Window
{
public void TheadFunction ()
{
while (true)
{
//Do some work
Thread.Sleep(50);
}
}
public Window1()
{
InitializeComponent();
Thread myThread = new Thread(ThreadFunction);
myThread.Start();
}
}
|