home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / ReadMe_xml_52________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Extensible Markup Language  |  2002-06-20  |  3.6 KB  |  59 lines

  1. <?xml version='1.0'?>
  2. <?xml-stylesheet type="text/xsl" href="..\..\..\readme.xsl"?>
  3.  
  4. <sample>
  5. <title>Monitor Synchronization Sample</title>
  6. <title-short>MonitorSynchronization</title-short>
  7. <overview>
  8.    This sample demonstrates how to use the Monitor class for thread synchronization. The sample queues up 5 asynchronous method calls.  Each method grabs the lock for <richcontent bold="T">this</richcontent><richcontent>, writes to the console, sleeps, and then writes to the console a second time. The Monitor type's static functions are used to enforce mutually exclusive access to a protected block of code.</richcontent>
  9. </overview>
  10. <subdirectory>Technologies\Threading\MonitorSynchronization</subdirectory>
  11. <buildsteps>
  12.    <step>
  13.       Type <richcontent bold="T">BUILD.bat</richcontent>
  14.       <richcontent> from the command line.</richcontent>      
  15.       <example>
  16.          C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\Threading\MonitorSynchronization\VB>Build.bat
  17.       </example>
  18.    </step>
  19. </buildsteps>
  20. <runsteps>
  21.    <step>
  22.       Type <richcontent bold="T">Monitor.exe</richcontent><richcontent> from the command line.</richcontent>
  23.       <example>
  24.          C:\Program Files\Microsoft.NET\SDK\v1.1\Samples\Technologies\Threading\MonitorSynchronization\VB>Monitor.exe
  25.       </example>
  26.    </step>
  27.    <step>
  28.       Notice that the "Start Writing" and "Stop Writing" output for each writer is output one after the other without overlap from threads with different ID's.  This is because the threads hold exclusive access to the resource.
  29.    </step>
  30. </runsteps>
  31. <technologies>
  32.    <technology name = "Thread Synchronization" keyword="T">
  33.       <class name = "Monitor" keyword="T">
  34.          The Monitor class consists of static functions for entering and exiting a protected block of code. You cannot instantiate an instance of the Monitor type. Instead, you pass to its static functions a reference to any object-derived type that you wish to use as a single node of synchronization. <richcontent bold="T">Note:</richcontent><richcontent> Both Visual Basic and C# implement special keywords to take advantage of the Monitor type's static functions.  C# uses the </richcontent><richcontent bold="T">lock</richcontent><richcontent> keyword, and Visual Basic implements the </richcontent><richcontent bold="T">SyncLock</richcontent><richcontent>keyword.</richcontent>
  35.       </class>
  36.       <class name = "AutoResetEvent" keyword="T">
  37.          The sample's main thread waits on an AutoResetEvent object until it is set, which indicates that the last of the asynchronous functions are finished doing their work.
  38.       </class>
  39.       <class name = "Interlocked" keyword="T">
  40.          The sample uses the static Decrement() method of the Interlocked class to asynchronously access a counter variable to indicate when the AutoResetEvent should be set.
  41.       </class>
  42.    </technology>
  43.    <technology name = "Threading" keyword="T">
  44.       <class name = "ThreadPool" keyword="T">
  45.          When writing managed code, it is suggested that whenever possible, developers use the QueueUserWorkItem() method of the ThreadPool class to implement asynchronous method calls. This sample uses this approach to execute code that contends for a logical resource.
  46.       </class>
  47.    </technology>
  48.    <technology name = "Delegates" keyword="T">
  49.       <class name = "WaitCallback" keyword="T">
  50.          The WaitCallback delegate type is used by this sample to create a type-safe callback method for the ThreadPool class to use. 
  51.       </class>      
  52.    </technology>
  53. </technologies>
  54. <keywords>
  55.    <word name="Threads" keyword="T"/>
  56. </keywords>
  57. </sample>
  58.  
  59.