using System;
using System.Threading;
public class Work
{
public static void Main()
{
// To start a thread using a shared thread procedure, use
// the class name and method name when you create the
// ParameterizedThreadStart delegate. C# infers the
// appropriate delegate creation syntax:
// new ParameterizedThreadStart(Work.DoWork)
//
Thread newThread = new Thread(Work.DoWork);
// Use the overload of the Start method that has a
// parameter of type Object. You can create an object that
// contains several pieces of data, or you can pass any
// reference type or value type. The following code passes
// the integer value 42.
//
newThread.Start("My Data1","My Data2");
// To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ParameterizedThreadStart delegate. C# infers
// the appropriate delegate creation syntax:
// new ParameterizedThreadStart(w.DoMoreWork)
//
Work w = new Work();
newThread = new Thread(w.DoMoreWork);
// Pass an object containing data for the thread.
//
newThread.Start("My Data1","My Data2");
}
public static void DoWork(object data1,object data2)
{
Console.WriteLine("Static thread procedure. Data1='{0}'",
data1);
Console.WriteLine("Static thread procedure. Data2='{0}'",
data2);
}
public void DoMoreWork(object data1,object data2)
{
Console.WriteLine("Instance thread procedure. Data1='{0}'",
data1);
Console.WriteLine("Instance thread procedure. Data2='{0}'",
data2);
}
}
Imports System.Threading
Public Class Work
Public Shared Sub Main()
' To start a thread using a shared thread procedure, use
' the class name and method name when you create the
' ParameterizedThreadStart delegate. C# infers the
' appropriate delegate creation syntax:
' new ParameterizedThreadStart(Work.DoWork)
'
Dim newThread As New Thread(AddressOf Work.DoWork)
' Use the overload of the Start method that has a
' parameter of type Object. You can create an object that
' contains several pieces of data, or you can pass any
' reference type or value type. The following code passes
' the integer value 42.
'
newThread.Start("My Data1", "My Data2")
' To start a thread using an instance method for the thread
' procedure, use the instance variable and method name when
' you create the ParameterizedThreadStart delegate. C# infers
' the appropriate delegate creation syntax:
' new ParameterizedThreadStart(w.DoMoreWork)
'
Dim w As New Work()
newThread = New Thread(AddressOf w.DoMoreWork)
' Pass an object containing data for the thread.
'
newThread.Start("My Data1", "My Data2")
End Sub
Public Shared Sub DoWork(data1 As Object, data2 As Object)
Console.WriteLine("Static thread procedure. Data1='{0}'", data1)
Console.WriteLine("Static thread procedure. Data2='{0}'", data2)
End Sub
Public Sub DoMoreWork(data1 As Object, data2 As Object)
Console.WriteLine("Instance thread procedure. Data1='{0}'", data1)
Console.WriteLine("Instance thread procedure. Data2='{0}'", data2)
End Sub
End Class