<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.claritycon.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Coding Powers</title><subtitle type="html" /><id>http://blogs.claritycon.com/blogs/ryan_powers/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.claritycon.com/blogs/ryan_powers/atom.aspx" /><generator uri="http://communityserver.org" version="3.1.20917.1142">Community Server</generator><updated>2006-04-06T14:52:00Z</updated><entry><title>Facebook Developer Toolkit Explained at CNUG</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/11/19/3505.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/11/19/3505.aspx</id><published>2007-11-20T04:33:27Z</published><updated>2007-11-20T04:33:27Z</updated><content type="html">&lt;p&gt;I just finished presenting to the Chicago .NET User Group on Facebook Development using the Microsoft stack.&amp;nbsp; I focused primarily on the Facebook Developer Toolkit for obvious reasons (it is just what I know).&amp;nbsp; The session covered an overview of the Facebook API and the Facebook Platform.&amp;nbsp; We then talked in depth about using the Facebook Developer Toolkit to leverage the Facebook API and to write Canvas pages hosted within the Facebook Platform.&amp;nbsp; Thanks to my colleague Jonathan Schuster who did the code demos and saved me a bunch of prep time.&amp;nbsp; I was also able to demo leveraging Silverlight 1.1 on a Facebook IFrame Canvas page.&lt;/p&gt; &lt;p&gt;This is part of the deck where I described an overview of the Facebook Platform.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;a href="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitatCNUG_11D17/image.png"&gt;&lt;img height="228" alt="image" src="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitatCNUG_11D17/image_thumb.png" width="397" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;If you are new to the Facebook Platform, I'd recommend the recording we made of the session (linked at the end of this post) or check out the interview we did on Thirsty Developer&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The turn out was good.&amp;nbsp; I think we had 40+ people and most were new to Facebook development.&amp;nbsp; It was fun to introduce this platform to a new group of .net developers.&amp;nbsp; If you are interested in the presentation, the slides, demos and a video of the presentation can be accessed at &lt;a href="http://www.claritycon.com/claritytv/clarityTvWatch.aspx?id=14"&gt;clarityTV&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3505" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author></entry><entry><title>Facebook Developer Toolkit Version 1.3 Released</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/11/19/3504.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/11/19/3504.aspx</id><published>2007-11-20T04:32:17Z</published><updated>2007-11-20T04:32:17Z</updated><content type="html">&lt;p&gt;My thanks go out to my colleague Jonathan Schuster, who took over support of the &lt;a href="http://www.codeplex.com/FacebookToolkit"&gt;Facebook Developer Toolkit&lt;/a&gt; for the past few weeks.&amp;nbsp; He was able to push his way through a bunch of enhancements and bug fixes that the users have been waiting very patiently for.&amp;nbsp; &lt;/p&gt; &lt;p&gt;This release marks a good milestone for the Toolkit as the majority of known issues with the support of Canvas applications are solved.&amp;nbsp; In my opinion, the canvas support is now very solid and will really ease the learning curve for new developers who want to leverage the toolkit.&lt;/p&gt; &lt;p&gt;One of the big features of Release 1.3 is support for the compact framework.&amp;nbsp; Many thanks to Peter Foote who dedicated a bunch of time to work on these features.&amp;nbsp; For those of you interested, the release contains the following items.&lt;/p&gt; &lt;p&gt;&lt;a href="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitVersio.3Released_11B96/image.png"&gt;&lt;img height="492" alt="image" src="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitVersio.3Released_11B96/image_thumb.png" width="421" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Thanks to all of the people who have kept this project alive as I was pulled away.&amp;nbsp; Pretty cool.&amp;nbsp; We have had close to 500 downloads already.&amp;nbsp; I am hoping to re-engage and help add support for new things that Facebook is releasing.&lt;/p&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3504" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author></entry><entry><title>Hosting Vista File Previews in Managed Code</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/26/3245.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/26/3245.aspx</id><published>2007-07-26T21:14:00Z</published><updated>2007-07-26T21:14:00Z</updated><content type="html">&lt;P&gt;As part of my work on the Coding4Fun Developer Kit 2008, I created a WinForm control encapsulating the flow to display file previews.&amp;nbsp; The host is dependent on an improved version of Stephen Toub's framework, originally published &lt;A href="http://msdn.microsoft.com/msdnmag/issues/07/01/PreviewHandlers"&gt;here&lt;/A&gt;.&amp;nbsp; My enhancements were basically to make the COM wrapper classes public so that they can be used by the Managed PreviewHandlers and also by my Preview Handler Host.&amp;nbsp; The source for this project including the updated framework, Stephen's sample preview handlers, my host control and a sample application using the host control are available &lt;A href="http://employees.claritycon.com/rpowers/C4F/PreviewHandlers.zip"&gt;here&lt;/A&gt;.&amp;nbsp; Also, they can be downloaded from the codeplex project for the &lt;A href="http://www.codeplex.com/C4FDevKit"&gt;Coding4Fun Developer Kit 2008&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;A couple of quick notes before I describe how the managed preview handler host works.&amp;nbsp; &lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;For any of this to work, the C4F.DevKit.PreviewHandlerFramework.dll needs to be installed in GAC. 
&lt;LI&gt;Also, this host will work with all non-managed preview handlers and any managed preview handlers that were built against the PreviewHandlerFramework mentioned above.&amp;nbsp; Any Managed Preview Handlers that were compiled using Stephen's original framework or another method will not work with this host.&amp;nbsp; &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To host the results generated by any registered file preview handler in managed code, the PreviewHandlerFramework’s COM Wrappers are leveraged. In addition, part of this host needs to look up the preview handler that is currently registered with a particular file extension. To accomplish this, the PreviewHandlerHost leveraged the registry code from Stephen Toub’s Preview Handler Association Editor (&lt;A href="http://blogs.msdn.com/toub/archive/2006/12/14/preview-handler-association-editor.aspx"&gt;http://blogs.msdn.com/toub/archive/2006/12/14/preview-handler-association-editor.aspx&lt;/A&gt;). With the code to find the registered handler in hand, we constructed a control to implement the preview handler Data Flow as shown below (all of this code is part of PreviewHandlerHost project, PreviewHandlerHostControl.cs): 
&lt;UL&gt;
&lt;LI&gt;Declare an object that is the PreviewHandler (this will be cast to different COM Interfaces as needed) 
&lt;LI&gt;Unload any existing previews before generating a new preview 
&lt;UL&gt;
&lt;LI&gt;Call Unload of IPreviewHandler Interface (dDefined in PreviewHandlerFramework as a wrapper to existing COM interface)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;B&gt;Visual C#&lt;/B&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:e0faa62c-32c7-4b60-9182-71f5e78b5e05&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;private&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;object&lt;/SPAN&gt;&lt;SPAN&gt; _comInstance &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;null&lt;/SPAN&gt;&lt;SPAN&gt;; 
&lt;/SPAN&gt;&lt;SPAN&gt;private&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;void&lt;/SPAN&gt;&lt;SPAN&gt; GeneratePreview() 
{ 
&lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (_comInstance &lt;/SPAN&gt;&lt;SPAN&gt;!=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;null&lt;/SPAN&gt;&lt;SPAN&gt;) 
{ 
((IPreviewHandler)_comInstance).Unload(); 
}
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;Visual Basic&lt;/B&gt; 
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:4d96deec-86e6-4335-81f4-7c47cbee8c0c&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;Private&lt;/SPAN&gt;&lt;SPAN&gt; _filePath &lt;/SPAN&gt;&lt;SPAN&gt;As&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;String&lt;/SPAN&gt;&lt;SPAN&gt; 
&lt;/SPAN&gt;&lt;SPAN&gt;Private&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;Sub&lt;/SPAN&gt;&lt;SPAN&gt; GeneratePreview() 
&lt;/SPAN&gt;&lt;SPAN&gt;If&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;Not&lt;/SPAN&gt;&lt;SPAN&gt; _comInstance &lt;/SPAN&gt;&lt;SPAN&gt;Is&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;Nothing&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;Then&lt;/SPAN&gt;&lt;SPAN&gt; 
&lt;/SPAN&gt;&lt;SPAN&gt;CType&lt;/SPAN&gt;&lt;SPAN&gt;(_comInstance, IPreviewHandler).Unload() 
&lt;/SPAN&gt;&lt;SPAN&gt;End&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;If&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;UL&gt;
&lt;LI&gt;Build a RECT struct using the bounds of the visible area where the preview handler can draw. In this case, that is the full bounds of the PreviewHandlerHostControl&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;B&gt;Visual C#&lt;/B&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:7d849aa2-615e-4e29-be54-92f46c1a26c8&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;RECT r; 
r.top &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;; 
r.bottom &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.Height; 
r.left &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;; 
r.right &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.Width;
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;Visual Basic&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:ba216484-53ff-497e-846e-6cfbee439b30&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt;&lt;SPAN&gt; r &lt;/SPAN&gt;&lt;SPAN&gt;As&lt;/SPAN&gt;&lt;SPAN&gt; RECT 
r.top &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt; 
r.bottom &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;Me&lt;/SPAN&gt;&lt;SPAN&gt;.Height 
r.left &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt; 
r.right &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;Me&lt;/SPAN&gt;&lt;SPAN&gt;.Width
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Find the CLSID of the preview handler registered for the file extension of the file using registry lookup. This is typically done by looking in the registry under HKEY_CLASSES_ROOT\%file_extension%\shellex\{8895b1c6-b41f-4c1c-a562-0d564250836f}. This Registry key will have a value pointed to the Class ID (CLSID) of the COM registration of the registered preview handler. For more information about how preview handlers can be found in the registry, see this &lt;A href="http://msdn2.microsoft.com/en-us/library/aa969369.aspx"&gt;article&lt;/A&gt;. 
&lt;LI&gt;Create an instance of the preview handler using Reflection and the CLSID found in the registry.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;B&gt;Visual C#&lt;/B&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:c16e385d-6981-46a7-a3fb-01d8011523bf&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;Type comType &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; Type.GetTypeFromCLSID(&lt;/SPAN&gt;&lt;SPAN&gt;new&lt;/SPAN&gt;&lt;SPAN&gt; Guid(handler.ID)); 
_comInstance &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; Activator.CreateInstance(comType);
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;Visual Basic&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:29f6ea5a-c5d2-452a-8777-a6fa6d518514&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt;&lt;SPAN&gt; comType &lt;/SPAN&gt;&lt;SPAN&gt;As&lt;/SPAN&gt;&lt;SPAN&gt; Type &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; Type.GetTypeFromCLSID(&lt;/SPAN&gt;&lt;SPAN&gt;New&lt;/SPAN&gt;&lt;SPAN&gt; Guid(handler.ID)) 
_comInstance &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; Activator.CreateInstance(comType)
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Call the appropriate initialize for the create preview handler (either passing in a stream or filepath) 
&lt;UL&gt;
&lt;LI&gt;If the preview handler is a stream previewhandler, using a COM IStream Wrapper to handle Stream marshalling to COM&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;B&gt;Visual C#&lt;/B&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:4ddc20e8-4dde-4a50-9c86-c9c167f7157b&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (_comInstance &lt;/SPAN&gt;&lt;SPAN&gt;is&lt;/SPAN&gt;&lt;SPAN&gt; IInitializeWithFile) 
{ 
((IInitializeWithFile)_comInstance).Initialize(_filePath, &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;); 
} 
&lt;/SPAN&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (_comInstance &lt;/SPAN&gt;&lt;SPAN&gt;is&lt;/SPAN&gt;&lt;SPAN&gt; IInitializeWithStream) 
{ 
&lt;/SPAN&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; (File.Exists(_filePath)) 
{ 
StreamWrapper stream &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;new&lt;/SPAN&gt;&lt;SPAN&gt; StreamWrapper(File.Open(_filePath, FileMode.Open)); 
((VSExpressDevPack.PreviewHandlerFramework.IInitializeWithStream)_comInstance).Initialize(stream, &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;); 
} 
&lt;/SPAN&gt;&lt;SPAN&gt;else&lt;/SPAN&gt;&lt;SPAN&gt; 
{ 
&lt;/SPAN&gt;&lt;SPAN&gt;throw&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;new&lt;/SPAN&gt;&lt;SPAN&gt; Exception(&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;File not found&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;); 
} 
}
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;Visual Basic&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:7049fc2b-330c-478c-a66b-469818ceea07&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;If TypeOf _comInstance Is IInitializeWithFile Then 
CType(_comInstance, IInitializeWithFile).Initialize(_filePath, &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;) 
ElseIf TypeOf _comInstance Is IInitializeWithStream Then 
If File.Exists(_filePath) Then 
Dim stream As StreamWrapper &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; New StreamWrapper(File.Open(_filePath, FileMode.Open)) 
CType(_comInstance, VSExpressDevPack.PreviewHandlerFramework.IInitializeWithStream).Initialize(stream, &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;) 
Else 
Throw New Exception(&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;File not found&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;) 
End If 
End If
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Call SetWindow on the PreviewHandler, passing in a handle to the control and the bounds (RECT created earlier)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;B&gt;Visual C#&lt;/B&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:2f721402-8d99-4b35-ad10-f83642920e62&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;((IPreviewHandler)_comInstance).SetWindow(&lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.Handle, &lt;/SPAN&gt;&lt;SPAN&gt;ref&lt;/SPAN&gt;&lt;SPAN&gt; r);
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;Visual Basic&lt;/B&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:9f56952d-9c6c-4ecc-9c4a-96a6e417a738&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;CType&lt;/SPAN&gt;&lt;SPAN&gt;(_comInstance, IPreviewHandler).SetWindow(&lt;/SPAN&gt;&lt;SPAN&gt;Me&lt;/SPAN&gt;&lt;SPAN&gt;.Handle, r)
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;UL&gt;
&lt;LI&gt;Call DoPreview on the PreviewHandler&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;B&gt;Visual C#&lt;/B&gt; 
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:b45b3448-311d-4f54-b10e-a8faa468c676&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;((IPreviewHandler)_comInstance).DoPreview();
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;B&gt;Visual Basic&lt;/B&gt; 
&lt;P&gt; 
&lt;P&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:5603ceea-f2c3-4fcb-8475-7c341142c31a&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;CType&lt;/SPAN&gt;&lt;SPAN&gt;(_comInstance, IPreviewHandler).DoPreview()
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;If you are interested in more information, the zip file included with this project has all of the source and a document describing a walkthrough of using this control.&amp;nbsp; Additionally, the Coding4Fun Developer Pack 2008 Vol.1 Codeplex project has all the info and will also have any fixes/enhancements.&lt;/P&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3245" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /></entry><entry><title>Coding4Fun Developer Kit 2008 Vol.1 Beta Released on Codeplex</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/26/3244.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/26/3244.aspx</id><published>2007-07-26T21:13:00Z</published><updated>2007-07-26T21:13:00Z</updated><content type="html">&lt;P&gt;Recently, I have been spending most of my time helping put together the Coding4Fun Developer Kit that was released today on &lt;A href="http://www.codeplex.com/C4FDevKit"&gt;Codeplex&lt;/A&gt;.&amp;nbsp; This is a Kit put together by Microsoft to open up many of the new and powerful APIs avaiable in Vista and Visual Studio 2008 to enable simple programming interfaces that can be used from managed code.&lt;/P&gt;
&lt;P&gt;This developer kit contains .net wrappers and sample projects for the following Vista APIs&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Bluetooth 
&lt;LI&gt;Contacts 
&lt;LI&gt;Digital Sound Recording 
&lt;LI&gt;Messaging/Email 
&lt;LI&gt;Picture Sharing 
&lt;LI&gt;Picture Acquisition 
&lt;LI&gt;Power Management 
&lt;LI&gt;Preview Handlers 
&lt;LI&gt;Feeds 
&lt;LI&gt;Desktop Search&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I made two big contributions to this developer kit.&amp;nbsp; The first was building the Preview Handler Wrapper.&amp;nbsp; This Wrapper included enhancing the managed preview handler framework built by Stephen Toub and published in the &lt;A href="http://msdn.microsoft.com/msdnmag/issues/07/01/PreviewHandlers"&gt;January Edition of MSDN Magazine&lt;/A&gt;.&amp;nbsp; In addition, I wrote a managed preview handler host, to enable displaying any preview handler within a .net winform application.&amp;nbsp; Watch for my next post describing, Hosting File Previews In Managed Code.&amp;nbsp; My other contribution to the project was pulling the various projects together and building the installer.&amp;nbsp; I used &lt;A href="http://wix.sourceforge.net/"&gt;WIX&lt;/A&gt;.&amp;nbsp; It was a tedious process at times, but ultimately pretty effective.&amp;nbsp; I promise to write another post detailing my experience with WIX and what I did to put this installer together.&lt;/P&gt;
&lt;P&gt;Check out the codeplex site for the Coding4Fun Developer Kit 2008 vol.1.&amp;nbsp; Definitely some cool and interesting stuff.&lt;/P&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3244" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="ASP.NET" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET/default.aspx" /><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /><category term="ASP.NET 2.0" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET+2.0/default.aspx" /><category term="Windows Presentation Foundation (WPF)" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Presentation+Foundation+_2800_WPF_2900_/default.aspx" /><category term="ASP.NET" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET/default.aspx" /><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /><category term="Windows Presentation Foundation (WPF)" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Presentation+Foundation+_2800_WPF_2900_/default.aspx" /></entry><entry><title>SQL 2005 Performance Tuning using DMVs - Part 4 of 7 - I/O Health</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/06/3220.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/06/3220.aspx</id><published>2007-07-06T20:28:32Z</published><updated>2007-07-06T20:28:32Z</updated><content type="html">&lt;p&gt;In my previous 3 posts in this series, I went through an introduction to Dynamic Management Views and an in depth look at how DMVs can be used to analyze and pinpoint CPU bottlenecks.&amp;nbsp; In today's post we will take a look at using DMVs for analyzing I/O Health and pressure.&lt;/p&gt; &lt;p&gt;You can use the following DMV query to find currently pending I/O requests. You can execute this query periodically to check the health of I/O subsystem and to isolate physical disk(s) that are involved in the I/O bottlenecks.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt; &lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:783c7b17-9844-4b2e-9531-ccbda6c99fea"&gt;&lt;pre&gt;&lt;div&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt; 
    database_id, 
    &lt;/span&gt;&lt;span&gt;file_id&lt;/span&gt;&lt;span&gt;, 
    io_stall,
    io_pending_ms_ticks,
    scheduler_address 
&lt;/span&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt;    
    sys.dm_io_virtual_file_stats(&lt;/span&gt;&lt;span&gt;NULL&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;NULL&lt;/span&gt;&lt;span&gt;)t1
&lt;/span&gt;&lt;span&gt;INNER&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;JOIN&lt;/span&gt;&lt;span&gt;
       sys.dm_io_pending_io_requests &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; t2
&lt;/span&gt;&lt;span&gt;ON&lt;/span&gt;&lt;span&gt;    t1.file_handle &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; t2.io_handle&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;If you find, that you regularly have a high number of pending I/O requests, you can use the following query to determine which SQL batches use the most I/O.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;
&lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:367193bc-77b2-49dd-ae38-183c01fbb561"&gt;&lt;pre&gt;&lt;div&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;TOP&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;5&lt;/span&gt;&lt;span&gt; 
    (total_logical_reads&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;execution_count) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; avg_logical_reads,
    (total_logical_writes&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;execution_count) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; avg_logical_writes,
    (total_physical_reads&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;execution_count) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; avg_phys_reads,
     Execution_count, 
    statement_start_offset &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; stmt_start_offset, 
    st.&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;text&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;, 
    qp.query_plan
&lt;/span&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt; sys.dm_exec_query_stats  qs
&lt;/span&gt;&lt;span&gt;CROSS&lt;/span&gt;&lt;span&gt; APPLY sys.dm_exec_sql_text(qs.sql_handle) st
&lt;/span&gt;&lt;span&gt;CROSS&lt;/span&gt;&lt;span&gt; APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
&lt;/span&gt;&lt;span&gt;ORDER&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;BY&lt;/span&gt;&lt;span&gt; 
 (total_logical_reads &lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span&gt; total_logical_writes) &lt;/span&gt;&lt;span&gt;Desc&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;If you are troubleshooting blocked I/O realtime, you can use dm_tran_locks and dm_waiting_tasks to determine what sql is blocking and what is waiting.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;
&lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:e1b7bf55-6e66-45ca-a98b-8477c706bd56"&gt;&lt;pre&gt;&lt;div&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt; 
    t1.resource_type,
    &lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt;database&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;db_name&lt;/span&gt;&lt;span&gt;(resource_database_id),
    &lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt;blk object&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; t1.resource_associated_entity_id,
    t1.request_mode,
    t1.request_session_id,
    t2.blocking_session_id     
&lt;/span&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt; 
    sys.dm_tran_locks &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; t1
&lt;/span&gt;&lt;span&gt;INNER&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;JOIN&lt;/span&gt;&lt;span&gt; 
    sys.dm_os_waiting_tasks &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; t2
&lt;/span&gt;&lt;span&gt;ON&lt;/span&gt;&lt;span&gt; 
    t1.lock_owner_address &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; t2.resource_address &lt;/span&gt;&lt;span&gt;and&lt;/span&gt;&lt;span&gt;
    t1.request_session_id &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; t1.request_session_id
&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The last thing to check when analyzing I/O is the utlization of tempDB.&amp;nbsp; You can use dm_db_file_space_usage to determine the amount of space that is being used in tempdb by user_objects, internal_objects and the version_store.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;
&lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:c62c6ba8-41cd-4276-9176-79d4e43d36ae"&gt;&lt;pre&gt;&lt;div&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt;
    &lt;/span&gt;&lt;span&gt;SUM&lt;/span&gt;&lt;span&gt; (user_object_reserved_page_count)&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;8&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; user_objects_kb,
    &lt;/span&gt;&lt;span&gt;SUM&lt;/span&gt;&lt;span&gt; (internal_object_reserved_page_count)&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;8&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; internal_objects_kb,
    &lt;/span&gt;&lt;span&gt;SUM&lt;/span&gt;&lt;span&gt; (version_store_reserved_page_count)&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;8&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; version_store_kb,
    &lt;/span&gt;&lt;span&gt;SUM&lt;/span&gt;&lt;span&gt; (unallocated_extent_page_count)&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;8&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; freespace_kb
&lt;/span&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt; sys.dm_db_file_space_usage
&lt;/span&gt;&lt;span&gt;WHERE&lt;/span&gt;&lt;span&gt; database_id &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;That's it for this edition, in the next installment we will look at finding Problem Queries.&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;code from this post is available &lt;a href="http://employees.claritycon.com/rpowers/dmv/Demo4_IOHealth.sql"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3220" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="SQL Server 2005" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/SQL+Server+2005/default.aspx" /></entry><entry><title>Facebook Developer Toolkit Version 1.2 Released</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/06/3219.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/06/3219.aspx</id><published>2007-07-06T20:09:08Z</published><updated>2007-07-06T20:09:08Z</updated><content type="html">&lt;p&gt;I have been spending most of time working on the Facebook Developer Toolkit and monitoring our &lt;a href="http://www.codeplex.com/FacebookToolkit"&gt;codeplex site&lt;/a&gt;.&amp;nbsp; Things have been going pretty, the response has been pretty positive and the help from the other site contributors has been great.&amp;nbsp; We even just became the 10th most popular project on CodePlex.&amp;nbsp; Which is a pretty cool accomplishment and pretty impressive company.&lt;/p&gt; &lt;p&gt;&lt;a href="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitVersio.2Released_D513/image03.png"&gt;&lt;img height="253" src="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitVersio.2Released_D513/image0_thumb1.png" width="456" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Today, we released Version 1.2 of the Toolkit.&lt;/p&gt; &lt;p&gt;Included in this release are:&lt;/p&gt; &lt;li&gt;Refactored FacebookService  &lt;li&gt;Added AsyncFacebookService  &lt;li&gt;Refactored Parsers and Entities into their own directory and namespace  &lt;li&gt;Added improved photo api  &lt;li&gt;Added Canvas Base pages to Facebook.WebControls  &lt;li&gt;Added Canvas samples to Facebook.WebControls  &lt;li&gt;Added IFrame Ajax sample  &lt;li&gt;Added IFrame Silverlight Example  &lt;li&gt;Updated to new notifications API &lt;b&gt;*INTERFACE CHANGE*&lt;/b&gt; &lt;li&gt;Updated PublishStory and PublishAction interfaces &lt;b&gt;*INTERFACE CHANGE*&lt;/b&gt; &lt;li&gt;Updated CreateAlbum interface to return created Album &lt;b&gt;*INTERFACE CHANGE*&lt;/b&gt; &lt;li&gt;Added SetFBML override taking in userid  &lt;li&gt;Added small and big picture url and bitmap to photo and user  &lt;li&gt;Added GetFriendsNonAppUsers method&lt;/li&gt; &lt;p&gt;The major change is the Canvas base pages, these should help new developers solve the riddle of building Facebook Canvas applications.&lt;/p&gt; &lt;p&gt;Thanks to everyone who helped with code and feedback.&amp;nbsp; I think we continue to make good progress on this project.&amp;nbsp;&amp;nbsp;You can&amp;nbsp;download the release or documentation &lt;a href="http://www.codeplex.com/FacebookToolkit/Release/ProjectReleases.aspx?ReleaseId=5387"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3219" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="ASP.NET" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET/default.aspx" /><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /><category term="ASP.NET 2.0" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET+2.0/default.aspx" /><category term="ASP.NET" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET/default.aspx" /><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /></entry><entry><title>SQL 2005 Performance Tuning using DMVs - Part 3 of 7 - Alleviating CPU Pressure</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/02/3214.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/07/02/3214.aspx</id><published>2007-07-02T21:53:46Z</published><updated>2007-07-02T21:53:46Z</updated><content type="html">&lt;p&gt;This is the third installment on my series on using Dynamic Views to help with SQL 2005 performance tuning.&amp;nbsp; The previous post on Identifying CPU Pressure can be found &lt;a href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/13/3190.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;After identifying that a database is cpu constrained, the next step is to find out what is using all the cpu.&amp;nbsp; The first step is to identify the SQL batches that are using the most CPU.&amp;nbsp; To find these batches, you use dm_exec_query_stats and join to dm_exec_sql_text to get the actual SQL statement.&amp;nbsp;The following query will yield the top 10 (currently cached) sql statements for cpu utilization.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt; &lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:eb5d8df7-13ba-4514-a062-bf57031a2a4a"&gt;&lt;pre&gt;&lt;div&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt; 
    derived_table.total_cpu_time,
    derived_table.total_execution_count,
    derived_table.total_cpu_time&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;derived_table.total_execution_count &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; cpu_per_execution,
    derived_table.number_of_statements,
    Plans.query_plan
&lt;/span&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt;    
(
&lt;/span&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;TOP&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;span&gt; 
    &lt;/span&gt;&lt;span&gt;SUM&lt;/span&gt;&lt;span&gt;(qs.total_worker_time) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; total_cpu_time, 
    &lt;/span&gt;&lt;span&gt;SUM&lt;/span&gt;&lt;span&gt;(qs.execution_count) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; total_execution_count,
    &lt;/span&gt;&lt;span&gt;COUNT&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt;  number_of_statements, 
    qs.plan_handle
&lt;/span&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt; 
    sys.dm_exec_query_stats qs
&lt;/span&gt;&lt;span&gt;GROUP&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;BY&lt;/span&gt;&lt;span&gt; qs.plan_handle
&lt;/span&gt;&lt;span&gt;ORDER&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;BY&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;SUM&lt;/span&gt;&lt;span&gt;(qs.total_worker_time) &lt;/span&gt;&lt;span&gt;desc&lt;/span&gt;&lt;span&gt;) derived_table
&lt;/span&gt;&lt;span&gt;CROSS&lt;/span&gt;&lt;span&gt; APPLY sys.dm_exec_query_plan(plan_handle) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; Plans
&lt;/span&gt;&lt;span&gt;order&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;by&lt;/span&gt;&lt;span&gt; derived_table.total_cpu_time&lt;/span&gt;&lt;span&gt;/&lt;/span&gt;&lt;span&gt;derived_table.total_execution_count &lt;/span&gt;&lt;span&gt;desc&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Another common cause of CPU over-utilization on a database server is query optimization time.&amp;nbsp; If you take periodic snapshots of the dm_exec_query_optimizer_info DMV, you can get a good idea of the amount of time spent optimizing.&amp;nbsp; The other way to look at optimization time is to examine how often queries are recompiled.&amp;nbsp; The following SQL is useful for this examination:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;
&lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:577cd0d1-87ca-4e81-8ddc-771831104567"&gt;&lt;pre&gt;&lt;div&gt;&lt;span&gt;--&lt;/span&gt;&lt;span&gt;To examine queries that recompile often,&lt;/span&gt;&lt;span&gt;
--&lt;/span&gt;&lt;span&gt;plan_generation_num indicates the number of times &lt;/span&gt;&lt;span&gt;
--&lt;/span&gt;&lt;span&gt;the query has recompiled. &lt;/span&gt;&lt;span&gt;
--&lt;/span&gt;&lt;span&gt;The following sample query gives you the top 10 stored procedures &lt;/span&gt;&lt;span&gt;
--&lt;/span&gt;&lt;span&gt;that have been recompiled.&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;top&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;10&lt;/span&gt;&lt;span&gt;
    sql_text.&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;text&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;,
    sql_handle,
    plan_generation_num,
    execution_count,
    dbid,
    objectid 
&lt;/span&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt; 
    sys.dm_exec_query_stats a
    &lt;/span&gt;&lt;span&gt;CROSS&lt;/span&gt;&lt;span&gt; APPLY sys.dm_exec_sql_text(sql_handle) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; sql_text
&lt;/span&gt;&lt;span&gt;WHERE&lt;/span&gt;&lt;span&gt;
    plan_generation_num &lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;ORDER&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;BY&lt;/span&gt;&lt;span&gt; plan_generation_num &lt;/span&gt;&lt;span&gt;DESC&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Another common cause of high CPU database server is queries that require parallel processing.&amp;nbsp; You can use a combination of dm_exec_requests, dm_os_tasks and dm_exec_sessions to find all active requests utilizing parallel processing.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:e144def4-1d67-4b74-b041-85cb27044caf"&gt;&lt;pre&gt;&lt;div&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt; 
    r.session_id,
    r.request_id,
    &lt;/span&gt;&lt;span&gt;MAX&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;ISNULL&lt;/span&gt;&lt;span&gt;(exec_context_id, &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;)) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; number_of_workers,
    r.sql_handle,
    r.statement_start_offset,
    r.statement_end_offset,
    r.plan_handle
&lt;/span&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt; 
    sys.dm_exec_requests r
&lt;/span&gt;&lt;span&gt;INNER&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;JOIN&lt;/span&gt;&lt;span&gt; sys.dm_os_tasks t &lt;/span&gt;&lt;span&gt;on&lt;/span&gt;&lt;span&gt; r.session_id &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; t.session_id
&lt;/span&gt;&lt;span&gt;INNER&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;JOIN&lt;/span&gt;&lt;span&gt; sys.dm_exec_sessions s &lt;/span&gt;&lt;span&gt;on&lt;/span&gt;&lt;span&gt; r.session_id &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; s.session_id
&lt;/span&gt;&lt;span&gt;WHERE&lt;/span&gt;&lt;span&gt; 
    s.is_user_process &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0x1&lt;/span&gt;&lt;span&gt;
&lt;/span&gt;&lt;span&gt;GROUP&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;BY&lt;/span&gt;&lt;span&gt; 
    r.session_id, r.request_id, 
    r.sql_handle, r.plan_handle, 
    r.statement_start_offset, r.statement_end_offset
&lt;/span&gt;&lt;span&gt;HAVING&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;MAX&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;ISNULL&lt;/span&gt;&lt;span&gt;(exec_context_id, &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;)) &lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Alternatively, you can just identify all cached plans that allow parallel execution.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;
&lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:f0a65373-5446-4b79-a541-0055866d8588"&gt;&lt;pre&gt;&lt;div&gt;&lt;span&gt;SELECT&lt;/span&gt;&lt;span&gt; 
    p.&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;, 
    q.&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;,
    cp.plan_handle
&lt;/span&gt;&lt;span&gt;FROM&lt;/span&gt;&lt;span&gt; 
    sys.dm_exec_cached_plans cp
&lt;/span&gt;&lt;span&gt;CROSS&lt;/span&gt;&lt;span&gt; APPLY sys.dm_exec_query_plan(cp.plan_handle) p
&lt;/span&gt;&lt;span&gt;CROSS&lt;/span&gt;&lt;span&gt; APPLY sys.dm_exec_sql_text(cp.plan_handle) &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; q
&lt;/span&gt;&lt;span&gt;WHERE&lt;/span&gt;&lt;span&gt; 
    cp.cacheobjtype &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt;Compiled Plan&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt;
    &lt;/span&gt;&lt;span&gt;AND&lt;/span&gt;&lt;span&gt; p.query_plan.value(&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt;declare namespace p=&amp;quot;http://schemas.microsoft.com/sqlserver/2004/07/showplan&amp;quot;;
        max(//p:RelOp/@Parallel)&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt;float&lt;/span&gt;&lt;span&gt;'&lt;/span&gt;&lt;span&gt;) &lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This should help you identify and address the causes of high CPU usage.&amp;nbsp; Next installment will take a look at identifying I/O bottlenecks.&amp;nbsp; You can download the source for these examples &lt;a href="http://employees.claritycon.com/rpowers/dmv/Demo3_CPUUsers.sql"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3214" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="SQL Server 2005" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/SQL+Server+2005/default.aspx" /></entry><entry><title>Silverlight 1.1 on Facebook Canvas Page using ASP.NET and Facebook Developer Toolkit</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/27/3207.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/27/3207.aspx</id><published>2007-06-27T22:29:00Z</published><updated>2007-06-27T22:29:00Z</updated><content type="html">&lt;P&gt;A couple weeks ago, working with Microsoft we delivered the facebook developer toolkit to help developers write Facebook applications using .net.&amp;nbsp; Since then, we created a &lt;A href="http://www.codeplex.com/FacebookToolkit"&gt;codeplex&lt;/A&gt; project to help keep the toolkit up to date and relevant.&amp;nbsp; It has been fun, and the response/involvement from the community has been great.&lt;/P&gt;
&lt;P&gt;Yesterday, I spent some time working on how to build canvas pages leveraging the toolkit.&amp;nbsp; A canvas page is a page that is accessed directly within facebook.com and the result is integrated into the user experience on facebook. These canvas pages were a major part of the new F8 facebook platform.&amp;nbsp; For more information, check out the Facebook Developer &lt;A href="http://developers.facebook.com/"&gt;documentation&lt;/A&gt;.&amp;nbsp; Anyway, after struggling with the flow of authentication and application adding, I finally got it working and&amp;nbsp;created 2 new canvas base pages (one for FBML type and one for IFrame).&amp;nbsp; I posted on codeplex about the changes &lt;A href="http://www.codeplex.com/FacebookToolkit/Thread/View.aspx?ThreadId=11859"&gt;here&lt;/A&gt;.&amp;nbsp; I also posted some very simple Canvas page examples for both FBML and IFrame.&lt;/P&gt;
&lt;P&gt;Now that I had a good framework in place for building the canvas page,&amp;nbsp;I wanted to see if I could get a Silverlight control with Facebook context showing up in my IFrame canvas page.&amp;nbsp; From past experience, I knew there were some major obstacles.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Some namespaces used in the Facebook.dll (wrapper to the API) are not supported in Silverlight namespace.&amp;nbsp;&amp;nbsp;Most notably:&amp;nbsp;System.XML, System.Web. 
&lt;LI&gt;Silverlight 1.1 Alpha does not support cross domain posts. 
&lt;LI&gt;It will be tough to manage the facebook login process from the Silverlight control, since we can not show the facebook hosted login page.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;With this in mind, I had a plan.&amp;nbsp; And after a frustrating day, just got a Silverlight control showing on a canvas page with some facebook context.&amp;nbsp; Here's how.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Added a new webservice (SilverlightService.asmx) to my ASPNETPlatformSamples web site.&amp;nbsp; This webservice is a proxy used by the silverlight application to call facebook 
&lt;LI&gt;Updated the ASPNETPlatformSamples web.config to support the web service. 
&lt;LI&gt;Added a ScriptService attribute to SilverlightService to enable it to support JSON calls 
&lt;LI&gt;Added WebMethod GetFriends wrapping the FacebookService.GetFriends(), this method needs to take the 4 parameters that comprise a facebook session, so that calls can maintain context. 
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:9b49ac3a-a3d9-45db-a517-ba1fc2afe5f9&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;[System.Web.Script.Services.ScriptService]
&lt;/SPAN&gt;&lt;SPAN&gt;public&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;class&lt;/SPAN&gt;&lt;SPAN&gt; SilverlightService : System.Web.Services.WebService
{
    Facebook.Components.FacebookService _fbService &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;new&lt;/SPAN&gt;&lt;SPAN&gt; Facebook.Components.FacebookService();


    [WebMethod]
    &lt;/SPAN&gt;&lt;SPAN&gt;public&lt;/SPAN&gt;&lt;SPAN&gt; UserJSON[] GetFriends(&lt;/SPAN&gt;&lt;SPAN&gt;string&lt;/SPAN&gt;&lt;SPAN&gt; api, &lt;/SPAN&gt;&lt;SPAN&gt;string&lt;/SPAN&gt;&lt;SPAN&gt; secret, &lt;/SPAN&gt;&lt;SPAN&gt;string&lt;/SPAN&gt;&lt;SPAN&gt; session, &lt;/SPAN&gt;&lt;SPAN&gt;string&lt;/SPAN&gt;&lt;SPAN&gt; userid)
    {
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;LI&gt;Created a stripped down version of the Facebook.Entity.User class that is serializiable by JSON.&amp;nbsp; JSON can't serialize enums or subclasses.&amp;nbsp; So, for this I just stripped them out.&amp;nbsp; This is called UserJSON&amp;nbsp;and is&amp;nbsp;currently&amp;nbsp;just a member of my ASPNETPlatformSamples web site.&amp;nbsp; 
&lt;LI&gt;In the GetFriends WebMethod, converted Collection of Users returned from Facebook call to Array of JSON compatible users. 
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:e6e4d4aa-eba1-414b-8463-2ce2340e41b2&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;        Collection&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;Facebook.Entity.User&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt; friends &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; _fbService.GetFriends();
        UserJSON[] x &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; UserJSON.ConvertFacebookUserArray(friends);
        &lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;SPAN&gt; x;
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;LI&gt;Created a new Canvas page (IFrame\Silverlight.aspx),&amp;nbsp;alongside to my other IFrame canvas samples 
&lt;LI&gt;Added a placeholder for the&amp;nbsp;Silverlight control and 4 hidden fields to store the facebook context. 
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:fd9dbaca-74b9-429e-af2c-9f95032eeba7&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;head&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
    &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;title&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;Silverlight Project Test Page &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN&gt;title&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
    
    &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;script type&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;text/javascript&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; src&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;Silverlight.js&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN&gt;script&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
    &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;script type&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;text/javascript&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; src&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;CreateSilverlight.js&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN&gt;script&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN&gt;head&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;

&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;body&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;form id&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;Form1&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; runat&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;server&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;asp:HiddenField ID&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;hidAPI&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; runat&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;server&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;asp:HiddenField ID&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;hidSecret&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; runat&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;server&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;asp:HiddenField ID&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;hidSession&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; runat&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;server&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;asp:HiddenField ID&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;hidUser&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; runat&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;server&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;/&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
    &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;div id&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;SilverlightControlHost&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
        &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt;script type&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;text/javascript&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
            createSilverlight();
        &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN&gt;script&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
    &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN&gt;div&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN&gt;form&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;LI&gt;Added code in code-behind to populate hidden fields (so they can be accessed by silverlight control). 
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:5af2dffd-a9f5-4ab1-9257-d6bf826a08ad&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;public&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;partial&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;class&lt;/SPAN&gt;&lt;SPAN&gt; _Default : CanvasIFrameBasePage 
{
    &lt;/SPAN&gt;&lt;SPAN&gt;private&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;const&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;string&lt;/SPAN&gt;&lt;SPAN&gt; FACEBOOK_API_KEY &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;c559128010f3edee33796fd4205361c2&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;;
    &lt;/SPAN&gt;&lt;SPAN&gt;private&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;const&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;string&lt;/SPAN&gt;&lt;SPAN&gt; FACEBOOK_SECRET &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;85887d1c9a8334e5059742468a5400ee&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;;

    &lt;/SPAN&gt;&lt;SPAN&gt;new&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;protected&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;void&lt;/SPAN&gt;&lt;SPAN&gt; Page_Load(&lt;/SPAN&gt;&lt;SPAN&gt;object&lt;/SPAN&gt;&lt;SPAN&gt; sender, EventArgs e)
    {
        &lt;/SPAN&gt;&lt;SPAN&gt;base&lt;/SPAN&gt;&lt;SPAN&gt;.Api &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; FACEBOOK_API_KEY;
        &lt;/SPAN&gt;&lt;SPAN&gt;base&lt;/SPAN&gt;&lt;SPAN&gt;.Secret &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; FACEBOOK_SECRET;
        &lt;/SPAN&gt;&lt;SPAN&gt;base&lt;/SPAN&gt;&lt;SPAN&gt;.Page_Load(sender, e);
        hidAPI.Value &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.FBService.ApplicationKey;
        hidSecret.Value &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.FBService.Secret;
        hidSession.Value &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.FBService.SessionKey;
        hidUser.Value &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;this&lt;/SPAN&gt;&lt;SPAN&gt;.FBService.UserId;

    }
}
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;LI&gt;Created a new silverlight project using Orcas called SilverlightWebServiceClient 
&lt;LI&gt;Added a web reference to the above WebService 
&lt;LI&gt;Added code in page_loaded event handler of xaml code behind to call the GetFriends method&amp;nbsp;on the WebService to retrieve an&amp;nbsp;array of friends. 
&lt;LI&gt;Then simply wrote&amp;nbsp;text to a textblock with the count that was found. 
&lt;LI&gt;I then needed to add a Silverlight Reference into&amp;nbsp;the ASPNETPlatformSamples.&amp;nbsp; This essentially copies the .xaml from the&amp;nbsp;Silverproject, and the compiled .xaml.cs into a ClientBin folder of the web site project so they can be accessed from within the website. 
&lt;LI&gt;You can see it in action, by going to my IFrame canvas &lt;A href="http://apps.facebook.com/aspnetcanvasiframe"&gt;sample&lt;/A&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;After logging in and adding the application, you should have a Silverlight demo link which will show the Silverlight page.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;A href="http://employees.claritycon.com/rpowers/Silverlig.NETandFacebookDeveloperToolkit_F607/image04.png"&gt;&lt;IMG height=301 src="http://employees.claritycon.com/rpowers/Silverlig.NETandFacebookDeveloperToolkit_F607/image0_thumb2.png" width=420 border=0&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;I checked the updated c# code for ASPNETPlatformSamples and a new project for the Silverlight Control into the codeplex &lt;A href="http://www.codeplex.com/FacebookToolkit/SourceControl/ListDownloadableCommits.aspx"&gt;site&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Now we need to build some cool Silverlight canvas apps.&amp;nbsp; If anyone has better ways to do this, I'd be interested in learning about them.&lt;/P&gt;
&lt;P&gt;Next up, Silverlight in FBML Canvas page.&lt;/P&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3207" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="ASP.NET 2.0" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET+2.0/default.aspx" /></entry><entry><title>SQL 2005 Performance Tuning using DMVs - Part 2 of 7 - Identifying CPU Pressure</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/13/3190.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/13/3190.aspx</id><published>2007-06-13T13:57:00Z</published><updated>2007-06-13T13:57:00Z</updated><content type="html">&lt;P&gt;In the my first &lt;A href="/blogs/ryan_powers/archive/2007/06/12/3189.aspx"&gt;post&lt;/A&gt; on DMVs, I gave an introduction to Dynamic Management Views and talked about some of the tuning activities that DMVs make easier.&amp;nbsp; I also gave my top 10 DMV list.&lt;/P&gt;
&lt;P&gt;In this installment, I am going to review how DMVs can be used to analyze CPU utilization on a machine running SQL Server.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Identifying if a System has CPU Pressure&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Prior to DMVs, the typical approach to checking whether a server was experiencing CPU bottlenecks was to use the Processor Queue Length performance counter.&amp;nbsp; This counter should typically be near 0 for systems not experiencing CPU pressure.&lt;/P&gt;
&lt;P&gt;This approach is still valid, but is not necessarily a good measure for a server used for SQL Server.&amp;nbsp; To see why this is the case, we must&amp;nbsp;examine SQL Server Execution Model. &lt;/P&gt;
&lt;P&gt;SQL Server uses a User Mode Scheduler (UMS) to control the execution of SQL Server user requests (SPIDs or session_ids). The UMS manages the execution of SQL Server requests (without returning control to Windows). So when SQL Server gets its time slice from the Windows scheduler, the SQL Server UMS manages what user requests are run during this time. &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;In a 4-proc scenario, there will be 4 User Mode Schedulers, one for each CPU. Each UMS uses a number of constructs (queues, lists and worker threads) to govern execution. At any given time, each UMS will have at most a single running thread, a runnable queue of requests that are &lt;BR&gt;waiting for CPU, a waiter list (for resources such as IO, locks, memory), and a work queue (user requests that are waiting for worker threads). &lt;/P&gt;
&lt;P&gt;Whenever the current running thread needs I/O it is moved to the wait list.&amp;nbsp; When this occurs, the next request from the runnable queue is started.&amp;nbsp; When the thread&amp;nbsp;needing I/O completes, it is moved back to the end of the&amp;nbsp;runnable queue.&amp;nbsp; 
&lt;P&gt;The time waiting for a resource is shown as Resource Waits. The time waiting in the runnable queue for CPU is called Signal Waits. In SQL Server 2005, waits are shown in the Dynamic Management View (DMV), sys.dm_os_wait_stats.&amp;nbsp; In this DMV, high Signal Wait % indicates&amp;nbsp;a CPU constraint.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;The query to measure cpu pressure using sys.dm_os_wait_stats is as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:5acafadb-2a9f-45ed-ae17-e872d3093567&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;SELECT&lt;/SPAN&gt;&lt;SPAN&gt;     
    &lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;(signal_wait_time_ms) &lt;/SPAN&gt;&lt;SPAN&gt;AS&lt;/SPAN&gt;&lt;SPAN&gt; signal_wait_time_ms,
    &lt;/SPAN&gt;&lt;SPAN&gt;cast&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;100.0&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;*&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;(signal_wait_time_ms) &lt;/SPAN&gt;&lt;SPAN&gt;/&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt; (wait_time_ms) &lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; numeric(&lt;/SPAN&gt;&lt;SPAN&gt;20&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;)) &lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;%signal (cpu) waits&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;,
    &lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;(wait_time_ms &lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt; signal_wait_time_ms) &lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; resource_wait_time_ms,
    &lt;/SPAN&gt;&lt;SPAN&gt;cast&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;100.0&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;*&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt;(wait_time_ms &lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt; signal_wait_time_ms) &lt;/SPAN&gt;&lt;SPAN&gt;/&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;sum&lt;/SPAN&gt;&lt;SPAN&gt; (wait_time_ms) &lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; numeric(&lt;/SPAN&gt;&lt;SPAN&gt;20&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;)) &lt;/SPAN&gt;&lt;SPAN&gt;as&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;%resource waits&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;
&lt;/SPAN&gt;&lt;SPAN&gt;FROM&lt;/SPAN&gt;&lt;SPAN&gt; 
    sys.dm_os_wait_stats
&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also monitor the SQL Server schedulers using the sys.dm_os_schedulers view to see if&lt;BR&gt;the number of runnable tasks is typically nonzero. A nonzero value indicates that tasks have to wait for their time slice to run; high values for this counter are a symptom of a CPU bottleneck. You can use the following query to list all the schedulers and look at the number of runnable tasks. 
&lt;P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:505a9cbb-54dd-4337-b0a2-08114b1ae1c1&gt;&lt;PRE&gt;&lt;DIV&gt;&lt;SPAN&gt;SELECT&lt;/SPAN&gt;&lt;SPAN&gt; 
    scheduler_id,
    current_tasks_count,
    runnable_tasks_count
&lt;/SPAN&gt;&lt;SPAN&gt;FROM&lt;/SPAN&gt;&lt;SPAN&gt;
    sys.dm_os_schedulers
&lt;/SPAN&gt;&lt;SPAN&gt;WHERE&lt;/SPAN&gt;&lt;SPAN&gt;  
    scheduler_id &lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN&gt;255&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;That's it for this installment, see you next time as we find out how to determine the likely causes of the CPU pressure we just identified.&lt;/P&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3190" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="SQL Server 2005" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/SQL+Server+2005/default.aspx" /></entry><entry><title>SQL 2005 Performance Tuning using DMVs - Part 1of 7</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/12/3189.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/12/3189.aspx</id><published>2007-06-12T06:47:00Z</published><updated>2007-06-12T06:47:00Z</updated><content type="html">&lt;P&gt;A few months ago, I researched and put together an internal presentation on one of the more interesting features in SQL 2005 (Dynamic Management Views).&amp;nbsp; This topic is not quite as cutting edge now as it was when I researched it.&amp;nbsp; But, I think it is still useful to blog what I found.&amp;nbsp; First off, thanks to Kim Tripp at SQL at &lt;A href="http://www.sqlskills.com" target=_blank&gt;www.sqlskills.com&lt;/A&gt;.&amp;nbsp; I first became interested in this topic when watching some of her webcasts.&amp;nbsp; I also found many of my good samples of DMV useage from some of her posts.&lt;/P&gt;
&lt;P&gt;I am going to break this up into parts, this first part is just an intro.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Microsoft made a big effort with SQL Server 2005 to make the server more transparent to administrators and developers. The result is DMVs, which should make database tuning and maintenance easier.&lt;/P&gt;
&lt;P&gt;“DMVs can expedite the diagnosis process by eliminating the need to generate and analyze physical dumps in most cases. DMVs provide a simplified and familiar relational interface for getting critical system information. This information can be used for monitoring purposes to alert administrators to any potential problems. Or, the information can be polled and collected periodically for detailed analysis later.” 
&lt;P&gt;DMVs are very useful in diagnosing different SQL performance problems.&amp;nbsp; I will go into more specifics with the future posts here.&amp;nbsp; But in general, you will find great resources for looking into any of the following: 
&lt;UL&gt;
&lt;LI&gt;Resource Bottlenecks 
&lt;UL&gt;
&lt;LI&gt;CPU 
&lt;LI&gt;Memory 
&lt;LI&gt;I/O&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;TempDB Bottlenecks 
&lt;LI&gt;Slow Queries 
&lt;UL&gt;
&lt;LI&gt;Bad Plans 
&lt;LI&gt;Missing Indexes 
&lt;LI&gt;Blocking&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Index Fragmentation&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Here is a good list of the Naming Conventions of the DMVs that are available:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;CLR Related 
&lt;UL&gt;
&lt;LI&gt;dm_clr_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Database Related 
&lt;UL&gt;
&lt;LI&gt;dm_db_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Execution Related 
&lt;UL&gt;
&lt;LI&gt;dm_exec_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Full Text Search Related 
&lt;UL&gt;
&lt;LI&gt;dm_fts_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Index Related 
&lt;UL&gt;
&lt;LI&gt;dm_db_index_ 
&lt;LI&gt;dm_missing_index_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;SQL OS Related 
&lt;UL&gt;
&lt;LI&gt;dm_os_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;I/O Related 
&lt;UL&gt;
&lt;LI&gt;dm_io_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Query Notifications Related 
&lt;UL&gt;
&lt;LI&gt;dm_qn_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Replication Related 
&lt;UL&gt;
&lt;LI&gt;dm_repl_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Service Broker Related 
&lt;UL&gt;
&lt;LI&gt;dm_broker_&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Transaction Related 
&lt;UL&gt;
&lt;LI&gt;dm_tran_&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;After playing around with all the DMVs I could find, I put together a list of my 10 favorites:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;dm_exec_query_stats – performance stats of all queries 
&lt;LI&gt;dm_exec_sql_text – returns exact sql for entire batch given a sql handle 
&lt;LI&gt;dm_exec_query_plan – return query plan for entire batch given a plan handle 
&lt;LI&gt;dm_db_index_usage_stats – displays how often each index is used, show Read Seeks, Read Scans, Write Seeks and Write Scans 
&lt;LI&gt;dm_db_index_physical_stats – replace DBCC SHOWCONTIG used to check index fragmentation 
&lt;LI&gt;dm_db_index_operational_stats – use to check for index contention and blocking 
&lt;LI&gt;dm_os_wait_stats – Used to determine the types of waits (signal or resource that are occurring) 
&lt;LI&gt;dm_os_waiting_tasks – Used to help identify blocking 
&lt;LI&gt;dm_tran_locks – Used to help indentify blocking 
&lt;LI&gt;dm_os_performance_counters – Query Access to SQL Server Performance counters&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;The last thing I wanted to cover in this initial post, was just methods for writing queries to identify the DMVs and their types.&amp;nbsp; Some DMVs are actual views, while others are tabled valued functions.&amp;nbsp; Again, thanks to Kim Tripp for most of this knowledge.&lt;/P&gt;
&lt;P&gt;Download a script for identifying DMVs and syntax to querying each &lt;A title=Demo1_IdentifyDMVs.sql href="http://Employees.claritycon.com/rpowers/dmv/Demo1_IdentifyDMVs.sql"&gt;here&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3189" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="SQL Server 2005" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/SQL+Server+2005/default.aspx" /></entry><entry><title>Mixed Authentication- ASP.NET Forms and IIS 6.0 Windows Integrated</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/12/3187.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/12/3187.aspx</id><published>2007-06-12T05:41:00Z</published><updated>2007-06-12T05:41:00Z</updated><content type="html">&lt;P&gt;Recently I was working on a website that needed to leverage both Integrated Windows and Forms Authentication.&amp;nbsp; The idea is that this website has some users that are on Active Directory and should be able to gain access without being challenged from credentials when they are logged into the domain.&amp;nbsp; Additionally, these users should be allowed to enter their AD credentials and access the site if they access the site remotely (while not logged in to AD).&amp;nbsp; This is all handled by IIS Integrated Windows Authentication.&amp;nbsp; However, for our situation we also have users who are not in AD at all and need to access the site.&amp;nbsp; We preferred to not create AD accounts for these users just to permit access to the site.&amp;nbsp; The solution we wanted was try windows integrated, if it fails, use forms authentication.&amp;nbsp; This problem will go away with the integrated pipeline of IIS 7.0 (more on this with a later post).&amp;nbsp; But, in IIS 6.0 this problem proved very tough to solve.&lt;/P&gt;
&lt;P&gt;After doing some research,&amp;nbsp;we found this article.&amp;nbsp; &lt;A href="http://msdn2.microsoft.com/en-us/library/ms972958.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms972958.aspx&lt;/A&gt;.&amp;nbsp; This was a great article and provided the basic approach to the solution.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;To summarize&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Set site to use Forms Authentication 
&lt;LI&gt;Set web.config authorization to deny anonymous users 
&lt;LI&gt;You need to set one page in your web application to use Windows Integrated Authentication (this was a revelation to me, setting one page to different IIS authentication than others in same app).&amp;nbsp; In this case we call it WinLogin.aspx 
&lt;OL&gt;
&lt;LI&gt;In this page, capture the Request Variable "LOGON_USER" and then call FormsAuthentication.RedirectFromLoginPage. 
&lt;LI&gt;This allows you to mimick a forms logon for the windows user.&lt;/LI&gt;&lt;/OL&gt;
&lt;LI&gt;Set Forms loginUrl to page from step 3 
&lt;LI&gt;Handle Windows Integrated failures.&amp;nbsp; Add a custom handler for 401 errors, and in the static HTM page.&amp;nbsp; Use a javascript function to forward to the real ASP.NET forms login page (WebLogin.aspx).&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&lt;IMG alt="" src="http://msdn2.microsoft.com/ms972958.mixedsecurity_fig02(en-us,MSDN.10).gif" border=0&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;6.&amp;nbsp; Update web.config to allow anonymous access of WebLogin.aspx.&lt;/P&gt;
&lt;P&gt;7.&amp;nbsp; Redirect to original requested URL&lt;/P&gt;
&lt;P&gt;&lt;IMG alt="" src="http://msdn2.microsoft.com/ms972958.mixedsecurity_fig03(en-us,MSDN.10).gif" border=0&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This was very helpful and got us a solution that solved most problems.&amp;nbsp; However, we quickly ran into one problem that we couldn't live with.&amp;nbsp;For IE users who did not have our site as a "Trusted Site", Windows Integrated would popup a login dialog prompting for credentials prior to our custom 404 provider.&amp;nbsp; So, our non AD users would have to press cancel on this to get to our login form.&amp;nbsp; Just not acceptable.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Some more research brought us to another great post that ultimately gave us they framework for our solution.&amp;nbsp; The article that we used to help us solve this problem is here &lt;A title=http://glazkov.com/blog/credentials-screening/ href="http://glazkov.com/blog/credentials-screening/"&gt;http://glazkov.com/blog/credentials-screening/&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;We were not able to get his exact implementation working, and ended up changing the code quite a bit.&amp;nbsp; But, the essence of the approach is exactly as described in that post (and the subsequent updates).&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The short explanation of how this works is:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Create an HTTPModule to handle incoming requests 
&lt;LI&gt;In this module, emit a javascript function to try to load the page that is setup as requiring Windows Integrated.&amp;nbsp; 
&lt;LI&gt;Back in the module, check the LOGON_USER server variable.&amp;nbsp; (If javascript succeeded in accessing that file, this variable will be populated) 
&lt;LI&gt;Continue with redirect&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The key to the solution that solves the original problem is the javascript load of the page set to require Windows Integrated Authentication.&amp;nbsp; What this accomplishes is pre-empting the load of this&amp;nbsp;page that IIS will do and allows our code (in the handler) to respond the results of the check prior to IIS potentially popping up a dialog.&lt;/P&gt;
&lt;P&gt;The last thing we needed to do was simply added AD integration into the weblogin form.&amp;nbsp; So, we could still allow AD users who access the site without being logged into the domain use the domain credentials.&amp;nbsp; I will discuss this in my next post.&amp;nbsp; The code I am posting with this blog does not have the AD integration&amp;nbsp;on the login page itself.&amp;nbsp; (As it will take more work for me to factor that out into a digestable snippet).&lt;/P&gt;
&lt;P&gt;You can download a sample &lt;A href="http://employees.claritycon.com/rpowers/MixedAuthentication.zip"&gt;here&lt;/A&gt;.&amp;nbsp; &lt;/P&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3187" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="ASP.NET 2.0" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET+2.0/default.aspx" /></entry><entry><title>CNUG Silverlight Presentation</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/11/3186.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/11/3186.aspx</id><published>2007-06-12T04:48:00Z</published><updated>2007-06-12T04:48:00Z</updated><content type="html">&lt;P&gt;Our CTO, Jon Rauschenberger, and I did a presentation on Silverlight at the Chicago .NET User Group last week.&amp;nbsp; Jon presented the slides and I did a few technical demos.&amp;nbsp; The first demo included a simple introduction to Expression Blend and Media support.&amp;nbsp; The second demo included some programming Silverlight with .NET examples including HTML integration, POX, JSON WebServices, Proxy WebServices and some simple XAML constructs.&lt;/P&gt;
&lt;P&gt;The session was very well attended.&amp;nbsp; And we had some good discussions around the Silverlight architecture and where it really fits into the Microsoft development stack.&amp;nbsp; If you are interested in learning more about Silverlight, we recorded the session.&amp;nbsp; The recording and resources (deck and demos) are available here.&amp;nbsp; &lt;A href="http://www.claritycon.com/claritytv/"&gt;http://www.claritycon.com/claritytv/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3186" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="Windows Presentation Foundation (WPF)" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Presentation+Foundation+_2800_WPF_2900_/default.aspx" /><category term="Windows Presentation Foundation (WPF)" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Presentation+Foundation+_2800_WPF_2900_/default.aspx" /></entry><entry><title>Facebook Developer Toolkit Codeplex project</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/11/3185.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/06/11/3185.aspx</id><published>2007-06-12T04:44:00Z</published><updated>2007-06-12T04:44:00Z</updated><content type="html">&lt;P&gt;We started a CodePlex project to help keep the Facebook Developer Toolkit up to date and relevant.&amp;nbsp; The project can be found here &lt;A href="http://www.codeplex.com/FacebookToolkit"&gt;http://www.codeplex.com/FacebookToolkit&lt;/A&gt;.&amp;nbsp; Currently, I am working through some of the issues that have been identified and packaging up Version 1.1.&amp;nbsp; I am open to any and all help that anyone wants to contribute to the codeplex project.&lt;/P&gt;
&lt;P&gt;Should be fun and a good way to make sure the community is able to voice problems and get updated builds.&amp;nbsp; Thanks to Microsoft for the support and commitment to this project.&lt;/P&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3185" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="ASP.NET" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET/default.aspx" /><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /><category term="ASP.NET 2.0" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET+2.0/default.aspx" /><category term="ASP.NET" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET/default.aspx" /><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /></entry><entry><title>Facebook Developer Toolkit Released</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/05/29/3149.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2007/05/29/3149.aspx</id><published>2007-05-29T22:27:44Z</published><updated>2007-05-29T22:27:44Z</updated><content type="html">&lt;p&gt;The Facebook Developer Toolkit that I&amp;nbsp;have been&amp;nbsp;working on the past month or so&amp;nbsp;was just released&amp;nbsp;on the Visual Studio Express Website at &lt;a href="http://msdn.microsoft.com/vstudio/express/showcase"&gt;http://msdn.microsoft.com/vstudio/express/showcase...&lt;/a&gt;.&amp;nbsp; This toolkit should really help improve the programming experience of using the Facebook API using Microsoft tools (like C# and VB.net).&amp;nbsp;&amp;nbsp;Below is a summary of&amp;nbsp;all the features available in the toolkit.&amp;nbsp; The toolkit is completely open source and has all code available in both C# and VB.net&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Facebook API Wrapper&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The Facebook.dll &amp;nbsp;is a wrapper to the Facebook API.&amp;nbsp; In our opinion, this is a more complete wrapper than the client libraries available in other languages.&amp;nbsp; In our wrapper, we have created strongly typed objects for all Facebook entities.&amp;nbsp; This will greatly simplify the programming experience of anyone using the Wrapper.&amp;nbsp; Developers accessing the API through the FacebookService component within our Facebook.dll will not need to understand the Facebook Authentication model or know how to work with the XML returned from the calls.&amp;nbsp; All of this is abstracted from the developer, as shown below.&amp;nbsp; (This sample assumes you already have an instance of FacebookService)&lt;/p&gt; &lt;p&gt;&lt;b&gt;&lt;/b&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:881be071-8bcc-4134-ba5b-5b2bcf60f582"&gt;Visual C#&lt;pre&gt;&lt;div&gt;&lt;span&gt;using&lt;/span&gt;&lt;span&gt; System.Collections.Generic; 
&lt;/span&gt;&lt;span&gt;using&lt;/span&gt;&lt;span&gt; System.Collections.ObjectModel; 
...

Collection&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;User&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; friends &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; FacebookService1.GetFriends(); 
&lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt;(friends.Count &lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;) 
{ 
     &lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt; firstFriendName &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; friends[&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;].Name;
} 
&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:0014dff1-f642-4d4e-b6d6-4f4cf5833313"&gt;VB.Net&lt;pre&gt;&lt;div&gt;&lt;span&gt;Imports&lt;/span&gt;&lt;span&gt; System.Collections.Generic 
&lt;/span&gt;&lt;span&gt;Imports&lt;/span&gt;&lt;span&gt; System.Collections.ObjectModel 
… 
&lt;/span&gt;&lt;span&gt;Dim&lt;/span&gt;&lt;span&gt; friends &lt;/span&gt;&lt;span&gt;As&lt;/span&gt;&lt;span&gt; Collection(&lt;/span&gt;&lt;span&gt;Of&lt;/span&gt;&lt;span&gt; User) &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; FacebookService1.GetFriends() 
&lt;/span&gt;&lt;span&gt;If&lt;/span&gt;&lt;span&gt; friends.Count &lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;Then&lt;/span&gt;&lt;span&gt;
     &lt;/span&gt;&lt;span&gt;dim&lt;/span&gt;&lt;span&gt; firstFriendName &lt;/span&gt;&lt;span&gt;as&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;string&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; friends(&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;).Name
&lt;/span&gt;&lt;span&gt;End&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;If&lt;/span&gt;&lt;span&gt; 
&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Infinite Session Support&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;One other interesting feature of the Facebook API is infinite sessions.&amp;nbsp; Infinite sessions is a concept that Facebook introduced to try to simplify the login process for third party applications.&amp;nbsp; In this case, when a user logs in to an application they can specify that the application can use their credentials forever (without redirecting to the Facebook login page).&amp;nbsp; In order to take advantage of this feature, an application needs a way to identify a user and associate them with their known Facebook Session identifier.&amp;nbsp; If an application has knowledge of who the user is and tracked their session key from previous Usage.&amp;nbsp; The application can set the UserId and SessionKey properties on the FacebookService component before making any api calls.&amp;nbsp; If this is done and the session/user combination is valid, the application&amp;nbsp;will avoid further login attempts.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Windows and Web Controls&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Another feature that is included in the Facebook Developer Toolkit are controls for simplifying Web and Windows Development.&amp;nbsp; These controls are installed in the Visual Studio Toolbar (in all editions of Visual Studio 2005) and allow the&amp;nbsp;developer to simply drag the control from the toolbar to the form or webform.&amp;nbsp; After the controls are added, the developer must just set the relevant control property with data retrieved using the FacebookService component described above.&amp;nbsp; The controls themselves contain very simple User Interfaces but demonstrate how to build controls for these environments and good practices for leveraging the FacebookService data.&amp;nbsp; The Controls that are available are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Friend List (Web and Windows) 
&lt;li&gt;User Profile (Web and Windows) 
&lt;li&gt;Photo Album (Web and Windows) 
&lt;li&gt;Friend Map (Windows only) 
&lt;li&gt;Event List (Windows only)&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Windows Presentation Foundation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The Facebook Developer Toolkit also includes a sample application showing how the FacebookService can be leveraged from a Windows Application using Windows Presentation Foundation (WPF).&amp;nbsp; The application is an animated rolodex, providing a visual display of a user's Facebook friends.&amp;nbsp; This application was developed by my colleague, Kevin Marshall.&amp;nbsp; It is a pretty cool sample and demo of some of the more compelling features of WPF.&amp;nbsp; Unfortunately, currently devlopers can not access the contact information for Facebook user's, so the Rolodex can only display generic user data rather than more useful information like address, phone number or email address.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitReleased_F58A/image01.png"&gt;&lt;img height="207" src="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitReleased_F58A/image0.png" width="240" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;LINQ and Orcas&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The last sample included in the Facebook Developer Toolkit&amp;nbsp;is a sample application showing how the FacebookService can be leveraged from&amp;nbsp;LINQ.&amp;nbsp; This application is called Friend Finder.&amp;nbsp; It shows how you can&amp;nbsp;use LINQ on top of the data returned from the&amp;nbsp;FacebookService to provide ordering,&amp;nbsp;filtering and paging.&amp;nbsp; This sample was coded by another colleague, Jerry Brunning and also shows a lot of the cool new langauage features available in Visual Studio codename "Orcas".&lt;/p&gt;
&lt;p&gt;&lt;a href="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitReleased_F58A/image03.png"&gt;&lt;img height="204" src="http://employees.claritycon.com/rpowers/FacebookDeveloperToolkitReleased_F58A/image02.png" width="240" border="0"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Documentation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The documetation included with the Facebook Developer Toolkit is pretty comprehensive.&amp;nbsp; It contains Code Snippets, Class Definitions and a Quick Start Guide.&amp;nbsp; You will have a link to the documentation in you Start Menu after installing and also it is available at c:\program files\coding4fun\facebook.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I hope everyone has fun trying out the toolkit, and let me know if you run into any problems.&lt;/p&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=3149" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /><category term="ASP.NET 2.0" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET+2.0/default.aspx" /><category term="Windows Forms" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/Windows+Forms/default.aspx" /></entry><entry><title>ASP.NET 2.0 Script Callbacks for Web Page AutoRefresh</title><link rel="alternate" type="text/html" href="http://blogs.claritycon.com/blogs/ryan_powers/archive/2006/04/06/353.aspx" /><id>http://blogs.claritycon.com/blogs/ryan_powers/archive/2006/04/06/353.aspx</id><published>2006-04-06T19:52:00Z</published><updated>2006-04-06T19:52:00Z</updated><content type="html">&lt;P class=MsoNormal&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;Recently I was working on a website requires client refresh when state changed on the server.&amp;nbsp; We wanted to implement this&amp;nbsp;without posting the page back to the server constantly.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The solution to this problem was to implement an out of band call (AJAX) to the server from a javascript timer.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This call can then check with the server if a post back should be done to refresh the system.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT face=Arial size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;To implement the out of band call, I used asp.net 2.0 script callbacks.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Script callbacks uses XmlHTTP to communicate with the server, and instead of the rs.htm and rs.asp file (like older techniques used to us) ASP.Net 2.0 uses the a script-library named CallBackManager.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT face=Arial size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;The client makes the call of a client-side method that will use the CallBackManager. The CallBackManager creates the request to an .aspx page on the server. The server processes the page and its events and makes the call of the sever-side function. The CallBackManager then parses the server response and make the call to a callback method located on the client-side. The CallBackManager must know the name of the client-side callback method. The CallbackManager must know which method it should call on the client-side. This is accomplished by using the GetCallBackEventReference method of the page. With this method we could also specify which method the CallbackManager should call if the server throws an exception.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT face=Arial size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;Let’s examine the code elements that are used to make this work. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT face=Arial size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;The System.Web.UI.ICallbackEventHandler must be implemented for using callback events. &lt;SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV class=code&gt;&lt;SPAN&gt;&lt;FONT color=blue&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=maroon&gt;%@&lt;/FONT&gt;&lt;FONT color=red&gt;&amp;nbsp;page&amp;nbsp;language&lt;/FONT&gt;&lt;FONT color=blue&gt;="C#"&lt;/FONT&gt;&lt;FONT color=red&gt;&amp;nbsp;%&lt;/FONT&gt;&lt;FONT color=blue&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT color=black&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT color=black&gt;&lt;/FONT&gt;&lt;FONT color=blue&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT color=maroon&gt;%@&lt;/FONT&gt;&lt;FONT color=red&gt;&amp;nbsp;implements&amp;nbsp;interface&lt;/FONT&gt;&lt;FONT color=blue&gt;="System.Web.UI.ICallbackEventHandler"&lt;/FONT&gt;&lt;FONT color=red&gt;&amp;nbsp;%&lt;/FONT&gt;&lt;FONT color=blue&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT color=black&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT color=black&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal align=left&gt;&lt;SPAN&gt;&lt;o:p&gt;&lt;FONT size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;SPAN&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/FONT&gt;
&lt;P class=MsoNormal align=left&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;The Code Behind for the page implementing ICallbackEventHandler must implement one method – RaiseCallbackEvent- to make the callback work. This method takes one argument which will contain the data from the client, and return a string value back to the client. In&amp;nbsp;my case the RaiseCallbackEvent checks if state on the server has changed (compared to the state in Session for this user).&amp;nbsp; If so, the client's view of the application should be refreshed.&amp;nbsp; _returnFromServer is&amp;nbsp;a private member variable of the codeBehind file that is set and used to return values to the client javascript method.&lt;/FONT&gt;&lt;/FONT&gt; 
&lt;P&gt;
&lt;DIV class=code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=blue&gt;public&amp;nbsp;void&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;RaiseCallbackEvent(&lt;/FONT&gt;&lt;FONT color=blue&gt;string&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;eventArgs)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;if&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;(Global.IsStateChagedChanged((&lt;/FONT&gt;&lt;FONT color=blue&gt;int&lt;/FONT&gt;&lt;FONT color=black&gt;)Session[&lt;/FONT&gt;&lt;FONT color=#808080&gt;"clientState"&lt;/FONT&gt;&lt;FONT color=black&gt;])&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;this&lt;/FONT&gt;&lt;FONT color=black&gt;._returnFromServer&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;=&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;"Do&amp;nbsp;Postback"&lt;/FONT&gt;&lt;FONT color=blue&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;this&lt;/FONT&gt;&lt;FONT color=black&gt;._returnFromServer&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;=&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;""&lt;/FONT&gt;&lt;FONT color=blue&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt; &lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P class=MsoNormal align=left&gt;&lt;SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;The next step is to set a reference within the CodeBehind to the client script that will be called back.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This is accomplished using the GetCallbackEventReference method.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This method has 3 overrides, in this case the following signature is used.&lt;SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV class=code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=blue&gt;public&amp;nbsp;string&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;GetCallbackEventReference(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Control&amp;nbsp;control,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;string&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;argument,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;string&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;clientCallback,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;string&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;context,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;string&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;clientErrorCallback)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt; &lt;/DIV&gt;
&lt;P class=MsoNormal align=left&gt;&lt;SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;The following code uses the GetCallbackEventReference to specify the client-side callback methods and the control that implements ICallbackEventHandler. In this example it’s the current page that has implemented the ICallbackEventHandler. So the current page object is passed to the method. When the server-side method has been executed the ClientCallback method on the client-side will be executed. If the servers throw an exception, the ClientErrorCallback will be executed on the client-side. The arg and ctx are names of the arguments of the client-side event that calls the server-side method.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This code is part of the Page_Load for the page.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV class=code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=blue&gt;string&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;src&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;=&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;Page.ClientScript.GetCallbackEventReference(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;this&lt;/FONT&gt;&lt;FONT color=black&gt;,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;"arg"&lt;/FONT&gt;&lt;FONT color=black&gt;,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;"ClientCallback_Refresh"&lt;/FONT&gt;&lt;FONT color=black&gt;,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;"ctx"&lt;/FONT&gt;&lt;FONT color=black&gt;,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;"ClientErrorCallback_Refresh"&lt;/FONT&gt;&lt;FONT color=black&gt;,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;false&lt;/FONT&gt;&lt;FONT color=black&gt;)&lt;/FONT&gt;&lt;FONT color=blue&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt; &lt;/DIV&gt;
&lt;P class=MsoNormal align=left&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal align=left&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;&lt;o:p&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;The code above provides the needed client reference for the loaded page.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In addition to this, the page needs to provide a javascript function that can be executed from the client to execute the call to the server.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This is done using the RegisterClientScriptBlock function as shown here.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt; 
&lt;P&gt;
&lt;DIV class=code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=blue&gt;string&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;mainSrc&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;=&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;@"function&amp;nbsp;CheckRefresh(arg,&amp;nbsp;ctx)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;"&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;+&amp;nbsp;src&amp;nbsp;+&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;";&amp;nbsp;}"&lt;/FONT&gt;&lt;FONT color=blue&gt;;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;Page.ClientScript.RegisterClientScriptBlock(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;this&lt;/FONT&gt;&lt;FONT color=black&gt;.GetType(),&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;"CheckRefresh"&lt;/FONT&gt;&lt;FONT color=black&gt;,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mainSrc,&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;true&lt;/FONT&gt;&lt;FONT color=black&gt;)&lt;/FONT&gt;&lt;FONT color=blue&gt;;&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;The RegisterClientScriptBlock above will generate in the rendered html to the client:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV class=code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=blue&gt;function&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;CheckRefresh(arg,&amp;nbsp;ctx)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WebForm_DoCallback(&lt;/FONT&gt;&lt;FONT color=#808080&gt;'__Page'&lt;/FONT&gt;&lt;FONT color=black&gt;,arg,ClientCallback_Refresh,ctx,ClientErrorCallback_Refresh,&lt;/FONT&gt;&lt;FONT color=blue&gt;false&lt;/FONT&gt;&lt;FONT color=black&gt;)&lt;/FONT&gt;&lt;FONT color=blue&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;}&lt;BR&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;This __doCallback method takes five arguments, the current page, the argument value sent into the RaiseCallbackMethod, the client-side callback method, the context value that will be sent to the client-side callback method, and the last argument is the client-side method that will be triggered if the server throws an exception.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;The last piece of code needed in the code-behind is a simple accessor method that provides access to member variable set during RaiseCallbackEvent that is used to return the result to the client scripts.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The GetCallbackResult is used for this.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV class=code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=blue&gt;public&amp;nbsp;string&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;GetCallbackResult()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;return&amp;nbsp;this&lt;/FONT&gt;&lt;FONT color=black&gt;._returnFromServer&lt;/FONT&gt;&lt;FONT color=blue&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;}&lt;BR&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;FONT face=Arial size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;With all the code in place in the code-behind, we need some simple javascript on the page to initiate the call back by executing the server generated CheckRefresh and checking the results.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;In this case, the timer method is executed every 10 seconds using the javascript function SetInterval(10000).&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV class=code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=blue&gt;function&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;CheckRefresh_Timer()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;myMessage.hide()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CheckRefresh(&lt;/FONT&gt;&lt;FONT color=#808080&gt;""&lt;/FONT&gt;&lt;FONT color=black&gt;,&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;""&lt;/FONT&gt;&lt;FONT color=black&gt;)&lt;/FONT&gt;&lt;FONT color=blue&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;function&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;ClientCallback_Refresh(&amp;nbsp;result,&amp;nbsp;context&amp;nbsp;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=darkgreen&gt;//&amp;nbsp;initiate&amp;nbsp;a&amp;nbsp;postback&amp;nbsp;to&amp;nbsp;refresh&amp;nbsp;data&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;if&lt;/FONT&gt;&lt;FONT color=black&gt;(result&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;==&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=#808080&gt;"Do&amp;nbsp;Postback"&lt;/FONT&gt;&lt;FONT color=black&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;__doPostBack(&lt;/FONT&gt;&lt;FONT color=#808080&gt;'ctl00$pageMainColumn$lbStateChange'&lt;/FONT&gt;&lt;FONT color=black&gt;,&lt;/FONT&gt;&lt;FONT color=#808080&gt;''&lt;/FONT&gt;&lt;FONT color=black&gt;)&lt;/FONT&gt;&lt;FONT color=blue&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=blue&gt;function&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;ClientErrorCallback_Refresh(&amp;nbsp;error,&amp;nbsp;context&amp;nbsp;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=darkgreen&gt;//log&amp;nbsp;or&amp;nbsp;ignore&amp;nbsp;error&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;}&lt;BR&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT face=Arial size=2&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;Notice that when&amp;nbsp;state changes, the page submits to the server via a button.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This allows a specifically targeted postback(ie. Fire a button event handler and the page_load with IsPostback = true)&amp;nbsp;to the server rather than a general page refresh.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;This is done by declaring an&amp;nbsp;“invisible” button.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;The code below shows the declaration of the button.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV class=code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=black&gt;&amp;lt;div&amp;nbsp;style&lt;/FONT&gt;&lt;FONT color=blue&gt;=&lt;/FONT&gt;&lt;FONT color=#808080&gt;"visibility:hidden;"&lt;/FONT&gt;&lt;FONT color=black&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;asp:LinkButton&amp;nbsp;ID&lt;/FONT&gt;&lt;FONT color=blue&gt;=&lt;/FONT&gt;&lt;FONT color=#808080&gt;"lbStateChange"&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;runat&lt;/FONT&gt;&lt;FONT color=blue&gt;=&lt;/FONT&gt;&lt;FONT color=#808080&gt;"server"&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;OnClick&lt;/FONT&gt;&lt;FONT color=blue&gt;=&lt;/FONT&gt;&lt;FONT color=#808080&gt;"lbStateChange_Click"&amp;nbsp;&lt;/FONT&gt;&lt;FONT color=black&gt;&amp;gt;state&amp;nbsp;change&amp;lt;/asp:LinkButton&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT face=Arial&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;P class=MsoNormal align=left&gt;&lt;SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal align=left&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal align=left&gt;&lt;SPAN&gt;The last important concept with respect to Script Callbacks is the execution of page_load.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;It is important to understand that the page_load of the page implementing the CallBackEventHandler is executed with Page.IsPostback = true each time a client calls back.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;Therefore, it is vital to ensure that this code path executes the smallest amount of code possible.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Overall, this seemed much more complicated that it actually was.&amp;nbsp; It is just a matter of putting all the pieces together.&amp;nbsp; The result is a client experience that can remain in synch with the server without disrupting general navigation and site usage.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.claritycon.com/aggbug.aspx?PostID=353" width="1" height="1"&gt;</content><author><name>rpowers</name><uri>http://blogs.claritycon.com/members/rpowers.aspx</uri></author><category term="ASP.NET 2.0" scheme="http://blogs.claritycon.com/blogs/ryan_powers/archive/tags/ASP.NET+2.0/default.aspx" /></entry></feed>