Thread.GetHashCode() : Thread « System.Threading « C# / C Sharp by API






Thread.GetHashCode()

  





using System;
using System.Collections.Generic;
using System.Text;

using System.Threading;

class AddParams {
    public int a;
    public int b;

    public AddParams(int numb1, int numb2) {
        a = numb1;
        b = numb2;
    }
}

class Program {
    public static void Add(object data) {
        if (data is AddParams) {
            Console.WriteLine("ID of thread in Add(): {0}",Thread.CurrentThread.GetHashCode());
            AddParams ap = (AddParams)data;
            Console.WriteLine("{0} + {1} is {2}", ap.a, ap.b, ap.a + ap.b);
        }
    }

    static void Main(string[] args) {
        Console.WriteLine("ID of thread in Main(): {0}", Thread.CurrentThread.GetHashCode());

        AddParams ap = new AddParams(10, 10);
        Thread t = new Thread(new ParameterizedThreadStart(Add));
        t.Start(ap);
        Console.ReadLine();
    }
}

   
    
  








Related examples in the same category

1.new Thread()
2.Thread.Abort()
3.Thread.AllocateDataSlot
4.Thread.AllocateNamedDataSlot
5.Thread.CurrentContext
6.Thread.CurrentCulture
7.Thread.CurrentThread
8.Thread.GetData
9.Thread.Interrupt()
10.Thread.IsAlive
11.Thread.IsBackground
12.Thread.Join()
13.Thread.Priority
14.Thread.ResetAbort()
15.Thread.SetData
16.Thread.Sleep
17.Thread.Start
18.Thread.ThreadState