.NET
  Home arrow .NET arrow Page 6 - Threading in Delphi for .NET
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Threading in Delphi for .NET
By: Xavier Pacheco
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 8
    2004-08-30

    Table of Contents:
  • Threading in Delphi for .NET
  • Threading
  • The System.Threading Namespace
  • Delegates in Delphi
  • Creating Threads Using Static Methods
  • Threading Priority
  • Apartment State and Thread Pooling Class
  • Timer Classes
  • Writing Thread-safe Code .NET Style
  • Mutex and Monitor Classes
  • Locks that Distinguish Between Readers and Writers
  • Events
  • Thread Local Storage
  • User Interface Issues
  • Threading Exceptions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Threading in Delphi for .NET - Threading Priority


    (Page 6 of 15 )

    System.Threading.ThreadPriority

    All manually created threads have an associated priority. This priority allows for boosting or lowering the scheduling of the thread. Table 14.1 lists the enumeration values for ThreadPriority, from the highest to lowest.

    Table 14.1 System.Threading.ThreadPriority Enumeration Values

    Value

    Description

    Highest

    Thread is scheduled before any other thread priority.

    AboveNormal

    Scheduled before any normal priority threads.

    Normal

    Default setting for threads. Scheduled before BelowNormal threads.

    BelowNormal

    Scheduled before any threads with lowest priority.

    Lowest

    Thread is scheduled after all other higher priority threads.


    A thread's priority is set using its Priority property. Be careful when changing priorities arbitrarily because that can cause hard to debug conditions such as thread starvation, race conditions, and deadlocks. Never use a higher priority when a lower priority will work.

    For GUI applications, most background threads should be set to BelowNormal or Lowest to ensure a responsive user interface no matter how much work the background threads are performing.

    System.Threading.ThreadState

    Once created, a thread has a state that indicates what the thread is doing. Table 14.2 contains the values of the ThreadState enumeration.

    Table 14.2 System.Threading.ThreadState Enumeration

    Value

    Description

    Running

    The thread's start method has been called.

    StopRequested

    Used internally only, indicates that the thread has been requested to stop executing.

    SuspendRequested

    The thread has been requested to suspend itself

    Background

    Controlled by the Thread.IsBackground property, this value indicates that the thread is executing in the background. Background threads are automatically aborted when the main thread terminates. Only foreground threads will prevent an application from exiting as long as they are running.

    Unstarted

    A thread has been created but not started yet.

    Stopped

    The thread is no longer executing.

    WaitSleepJoin

    The thread is not running due to either being blocked, sleeping, or joining (waiting for another thread to finish executing).

    Suspended

    The thread is suspended.

    AbortRequested

    The thread has been requested to abort, but has not received the ThreadAbortException yet.

    Aborted

    Indicates that the thread has been terminated because of Thread.Abort.


    Because a thread can be in multiple states, the ThreadState enumeration is a set of bit flags. Not all combinations are valid, however. One valid combination is a thread in a WaitSleepJoin state and an AbortRequested state.

    This chapter is from Delphi for .NET Developer's Guide, by Xavier Pacheco (Sams, 2004, ISBN: 0-672-32443-1). Check it out at your favorite bookstore today.

    Buy this book now.

    More .NET Articles
    More By Xavier Pacheco


     

    .NET ARTICLES

    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries
    - Introducing LINQ to SQL Designer using Visua...
    - Beginning LINQ to SQL Using Visual Studio 20...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway