| Author: Ketan A. Lohar 25 Jun 2008 | Member Level: Silver | Rating: Points: 1 |
Hi,
Refer following link http://www.yoda.arachsys.com/csharp/threads/
Regards, Ketan
|
| Author: Ratheesh 25 Jun 2008 | Member Level: Gold | Rating: Points: 1 |
.NET class Thread defined in the System.Threading namespace represents a managed thread. The Thread class offers raw control over the underlying operating system thread. However, with power comes liability, and usually most of the Thread class methods and properties should not be used by application developers. The article explains the rational behind its recommendations, and presents a higher-level wrapper class around the Thread type. The wrapper class provides only the safe methods, as well as compensates for basic deficiencies in the Thread class design.
Managing Thread ID You can get hold of the current thread your code runs on using the CurrentThread read-only static property of the Thread class:
public sealed class Thread { public static Thread CurrentThread { get; } // Other methods and properties }
." Multi-threading is probably one of the worst understood aspects of programming, and these days almost all application programmers need to understand it to some extent. This article acts as an introduction to multi-threading and gives some hints and tips for how to do it safely. Warning: I'm not an expert on the subject, and when the real experts start discussing it in detail, my head starts to spin somewhat. However, I've tried to pay attention to those who know what they're doing, and hopefully the contents of this article form at least part of a multi-threading "best practice".
|
| Author: Arun K 25 Jun 2008 | Member Level: Gold | Rating: Points: 6 |
Threading enables your C# program to perform concurrent processing so you can do more than one operation at a time. For example, you can use threading to monitor input from the user, perform background tasks, and handle simultaneous streams of input. The System.Threading namespace provides classes and interfaces that support multithreaded programming and enable you to easily perform tasks such as creating and starting new threads, synchronizing multiple threads, suspending threads, and aborting threads.
To incorporate threading in your C# code, simply create a function to be executed outside the main thread and point a new Thread object at it. The following code example creates a new thread in a C# application:
System.Threading.Thread newThread; newThread = new System.Threading.Thread(anObject.AMethod);
|
| Author: Ratheesh 26 Jun 2008 | Member Level: Gold | Rating: Points: 1 |
The .NET class Thread defined in the System.Threading namespace represents a managed thread. The Thread class offers raw control over the underlying operating system thread. However, with power comes liability, and usually most of the Thread class methods and properties should not be used by application developers. The article explains the rational behind its recommendations, and presents a higher-level wrapper class around the Thread type. The wrapper class provides only the safe methods, as well as compensates for basic deficiencies in the Thread class design.
Managing Thread ID You can get hold of the current thread your code runs on using the CurrentThread read-only static property of the Thread class:
public sealed class Thread { public static Thread CurrentThread { get; } // Other methods and properties }
|
| Author: Kumar Velu 22 Jul 2008 | Member Level: Diamond | Rating: Points: 6 |
Threading enables your C# program to perform concurrent processing so you can do more than one operation at a time. For example, you can use threading to monitor input from the user, perform background tasks, and handle simultaneous streams of input. The System.Threading namespace provides classes and interfaces that support multithreaded programming and enable you to easily perform tasks such as creating and starting new threads, synchronizing multiple threads, suspending threads, and aborting threads.
The following code example creates a new thread in a C# application:
System.Threading.Thread newThread; newThread = new System.Threading.Thread(anObject.AMethod);
The following code example starts a new thread in a C# application:
newThread.Start();
Multithreading is managed internally by a thread scheduler, a function the CLR typically delegates to the operating system. A thread scheduler ensures all active threads are allocated appropriate execution time, and that threads that are waiting or blocked – for instance – on an exclusive lock, or on user input – do not consume CPU time.
On a single-processor computer, a thread scheduler performs time-slicing – rapidly switching execution between each of the active threads. This results in "choppy" behavior, such as in the very first example, where each block of a repeating X or Y character corresponds to a time-slice allocated to the thread. Under Windows XP, a time-slice is typically in the tens-of-milliseconds region – chosen such as to be much larger than the CPU overhead in actually switching context between one thread and another (which is typically in the few-microseconds region).
On a multi-processor computer, multithreading is implemented with a mixture of time-slicing and genuine concurrency – where different threads run code simultaneously on different CPUs. It's almost certain there will still be some time-slicing, because of the operating system's need to service its own threads – as well as those of other applications.
A thread is said to be preempted when its execution is interrupted due to an external factor such as time-slicing. In most situations, a thread has no control over when and where it's preempted.
|
| Author: Ashok 23 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
1. Threads are basically light weight processes responsible for multitasking within a single application. 2. The base class used for threading is System.Threading. 3. Threads are managed under the Common Language Runtime, programmers don’t have to manage any threads explicitly. 4. Threads are implemented when you have situations in which you want to perform more then one task at a time. 5. In case of synchronization, since you have limited amount of recourses, you may have to restrict the access to the resources to one thread at a time. In these situations, you may implement locking on the threading to over come the scenarios. 6. An apartment is a logical container within a process and is used for objects that share the same thread-access requirement. Objects in the apartment can all receive method calls from any object in any thread in the apartment. And managed objects (object created within CLR) are responsible for thread safety. 7. Threads can be used under situations where we must wait for an event such as user input, a read from file, or receipt of data over the network.
|