added samples
[windows-sources.git] / sdk / samples / FrameworkSamples / CLR / Threading / Timers / readme.htm
blobf9a96c448550bfe00630046f3f9dc9c162873ea8
1 <html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=utf-8" /><META NAME="save" CONTENT="history" /><title xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Timers Technology Sample</title><META NAME="Description" CONTENT="&#xD;&#xA; This sample demonstrates the uses of timers in the common language runtime. The sample uses the T:System.Threading.Timer class to generate a periodic callback to a method. The sample creates a T:System.Threading.Timer and passes ..."></META><META NAME="MS.LOCALE" CONTENT="en-us" /><style>
2 body
3 {font-family:Verdana;font-size:medium;}
4 div#mainSection, div#header
5 {font-size:70%;width: 100%;}
6 div#mainBody
7 {font-size:90%;}
8 div#mainSection div table
9 {font-size: 100%;text-align: left;}
10 span#nsrTitle
11 {color:#003399;font-size:90%;font-weight:600;}
12 div#header
13 {background-color:#D4DFFF;}
14 .heading
15 {font-size:120%;color:#003399;}
16 .subHeading
17 {font-size:100%;margin-bottom:4;}
19 {margin-top:-2;margin-bottom:3;}
21 {margin-top:10;margin-bottom:5;}
22 div.tableSection p
23 {margin-top:1;margin-bottom:4;}
24 div#mainSection table th
25 {background-color:#EFEFF7;color:#000066;text-align:left;}
26 div#mainSection table td
27 {background-color:#F7F7FF;}
28 div#mainSection table
29 {margin-top:5px;margin-bottom: px;}
30 </style></head><body><div id="header"><table width="100%" id="topTable"></table></div><div id="mainSection"><div id="mainBody"><br /><font color="DarkGray">[This readme is a partial copy of the sample's topic in the SDK documentation.]</font><br /><font color="DarkGray" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt"></font><p xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt"></p><div class="introduction"><p xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
31 This sample demonstrates the uses of timers in the common language runtime. The sample uses the <span sdata="cer" target="T:System.Threading.Timer">Timer</span> class to generate a periodic callback to a method. The sample creates a <span sdata="cer" target="T:System.Threading.Timer">Timer</span> and passes to it a delegate. When the <span sdata="cer" target="T:System.Threading.Timer">Timer</span> fires, the delegate is invoked, and a static method is called asynchronously by a worker thread in the thread pool.
32 </p><p xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
33 For more information about using the samples, see the following topics:
34 </p><ul xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt"><li><p><span sdata="link">How to: View and Download Samples</span></p></li><li><p><span sdata="link">How to: Set Sample Settings</span></p></li></ul></div><h3 class="procedureSubHeading" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">To build the sample using the command prompt</h3><div class="subSection"><ol xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt"><li><p>
35 Open the Command Prompt window and navigate to one of the language-specific subdirectories for the sample.
36 </p></li><li><p>
37 Type <span class="input">msbuild TimersCS.sln</span> or <span class="input">msbuild TimersVB.sln</span>, depending on your choice of programming language, at the command line.
38 </p></li></ol></div><h3 class="procedureSubHeading" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">To build the sample using Visual Studio</h3><div class="subSection"><ol xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt"><li><p>
39 Open Windows Explorer and navigate to one of the language-specific subdirectories for the sample.
40 </p></li><li><p>
41 Double-click the icon for <b>TimersCS.sln</b> or <b>TimersVB.sln</b>, depending on your choice of programming language, to open the file in Visual Studio.
42 </p></li><li><p>
43 On the <span class="ui">Build</span> menu, click <span class="ui">Build Solution</span>.
44 </p></li></ol></div><h3 class="procedureSubHeading" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">To run the sample</h3><div class="subSection"><ol xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt"><li><p>
45 Navigate to the directory that contains the built executable, using the command prompt.
46 </p></li><li><p>
47 Type <span class="input">TimedCallback.exe</span> from the command line.
48 </p><div class="alert"><table width="100%" cellspacing="0" cellpadding="0"><tr><th align="left"><b>Note:</b></th></tr><tr><td><p>
49 This sample builds a console application. You must launch it from a console window in order to view its output.
52 </p></td></tr></table></div></li></ol></div><h1 class="heading" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt"><span onclick="ExpandCollapse(sectionToggle0)" style="cursor:default;" onkeypress="ExpandCollapse_CheckKey(sectionToggle0, event)" tabindex="0">Remarks</span></h1><div id="sectionSection0" class="section"><p xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
53 The following bullets briefly describe the technologies and classes used by this sample.
54 </p><ul xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt"><li><p><span class="label">Thread Timers</span></p><ul><li><p><span sdata="cer" target="T:System.Threading.Timer">Timer</span>Used to create periodic or singleton timers for relative or absolute times. The sample creates a periodic timer that invokes a delegate every two seconds until the application exits.
55 </p></li></ul></li><li><p><span class="label">Thread Pools</span> Although the <span sdata="cer" target="T:System.Threading.ThreadPool">ThreadPool</span> class is not explicitly referenced by this sample, the <span sdata="cer" target="T:System.Threading.Timer">Timer</span> class uses the thread pool managed by the common language runtime to invoke delegates asynchronously in response to timer events. The timer in this sample uses a worker thread in the pool every two seconds.
56 </p></li><li><p><span class="label">Delegates </span></p><ul><li><p><span sdata="cer" target="T:System.Threading.TimerCallback">TimerCallback</span>Used to create a typesafe callback method for the timer.
57 </p></li></ul></li></ul><p xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
58 For more information about using timers with asynchronous method calls, see the comments in the source code files.
59 </p></div><h1 class="heading" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt"><span onclick="ExpandCollapse(seeAlsoToggle)" style="cursor:default;" onkeypress="ExpandCollapse_CheckKey(seeAlsoToggle, event)" tabindex="0">See Also</span></h1><div id="seeAlsoSection" class="section"><h4 class="subHeading" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Concepts</h4><div class="seeAlsoStyle"><span sdata="link" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Threads and Threading</span></div><h4 class="subHeading" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Reference</h4><div class="seeAlsoStyle"><span sdata="cer" target="T:System.Threading.AutoResetEvent" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">AutoResetEvent</span></div><div class="seeAlsoStyle"><span sdata="cer" target="T:System.Delegate" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Delegate</span></div><div class="seeAlsoStyle"><span sdata="cer" target="T:System.Threading.Interlocked" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Interlocked</span></div><div class="seeAlsoStyle"><span sdata="cer" target="T:System.Threading.Mutex" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Mutex</span></div><div class="seeAlsoStyle"><span sdata="cer" target="N:System.Threading" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">System.Threading</span></div><div class="seeAlsoStyle"><span sdata="cer" target="T:System.Threading.ThreadPool" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">ThreadPool</span></div><div class="seeAlsoStyle"><span sdata="cer" target="T:System.Threading.WaitCallback" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">WaitCallback</span></div><div class="seeAlsoStyle"><span sdata="cer" target="T:System.Threading.WaitHandle" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">WaitHandle</span></div><div class="seeAlsoStyle"><span sdata="cer" target="T:System.Threading.Timer" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Timer</span></div><h4 class="subHeading" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Other Resources</h4><div class="seeAlsoStyle"><span sdata="link" xmlns:mshelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt">Threading Objects and Features</span></div></div></div></div></body></html>