Communicating Data to a Thread : Thread Creation « Thread « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Thread » Thread Creation 
20.1.9.Communicating Data to a Thread
using System;
using System.Threading;
   
class Sum {
    public Sum(int op1, int op2) {
        Console.WriteLine("[Sum.Sum] Instantiated with values of {0} and {1}", op1, op2);
        this.op1 = op1;
        this.op2 = op2;
    }
    int op1;
    int op2;
    int result;
    public int Resultget return result; } }
   
    public void Add()
    {
        Thread.Sleep(5000);
        result = op1 + op2;
    }
}
   
class ThreadData {
    static void Main() {
        Sum sum = new Sum(642);
   
        Thread thread = new Thread(new ThreadStart(sum.Add));
        thread.Start();
   
        for (int i = 0; i < 10; i++) {
            Thread.Sleep(200);
            Console.Write(".");
        }
        thread.Join();
   
        Console.WriteLine("[Main] The result is {0}", sum.Result);
        Console.ReadLine();
    }
}
20.1.Thread Creation
20.1.1.Thread method with parameter
20.1.2.Thread method with no parameter
20.1.3.The creation of threads
20.1.4.Create a thread of execution
20.1.5.Create multiple threads of execution
20.1.6.Passing an argument to the thread method.
20.1.7.Use anonymous delegate as the worker method to create Thread
20.1.8.Adding with Thread objects
20.1.9.Communicating Data to a Thread
20.1.10.Primary Thread statistcs
20.1.11.Starting a Method in a Separate Thread
20.1.12.Thread Stats
20.1.13.List threads for PID
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.