Wintellect  

I have been asked by many people if I will be updating my CLR via C# book for .NET 4.0.

Well, I'm happy to report that the answer is YES! I have already signed the contract with Microsoft Press and have been busy writing.

The new edition keeps its focus on the CLR and the C# language. And, since I didn't update the book for C# 3, I will actually be adding C# 3.0 content as well as C# 4.0 content. And, of course, I'll be covering the new features/changes between CLR 2.0 and 4.0.

The goal is to get the book out by the time .NET 4.0 ships. All looks good and I should easily be able to make this deadline.

Go here: http://channel9.msdn.com/shows/This+Week+On+Channel+9/This-Week-on-C9-Bing-Changes-to-NET-FX-40--play-Apple-IIe-games-on-your-Xbox/

And at about 23 minutes in, they talk briefly about the Wintellect Power Live Framework library.

Since late 2008, I have been spending a lot of time focusing on Microsoft’s Live Framework and Mesh technologies. Towards this end, I have produced a Power Live Framework library that simplifies coding against the Live Framework. And, I have also put together some sample applications that leverage my library. Furthermore, I have set up a Yahoo news group in order to support people that wish to use my library and sample code. The files and news group can be found here: http://tech.groups.yahoo.com/group/PowerLiveFx/.

The purpose of this blog post is to help you get started with programming for the Live Framework using my class library. For more information on the Live Framework in general, what it offers, and the concepts that surround it, I encourage you to see some of the videos from Microsoft’s PDC. Also, I will be speaking about Live Framework programming at Wintellect’s own Devscovery conference.

To develop against the Live Framework, you must:

·                     Provision your account:

o   Go to https://lx.azure.microsoft.com/Cloud/Provisioning/Default.aspx

o   From “New Project” page, click "Activate Live Framework CTP“

·                     If you want to access the Live Framework locally (not via the Internet), then download & run the developer client Live Operating Environment:

o   Go to https://developer.mesh-ctp.com/

o   Sign In, select “Add Device” and then install the client Live Operating Environment.

o   Then run “C:\Users\Jeffrey\AppData\Local\Microsoft\Live Framework Client\Bin\MeshAppMonitor.exe”.

o   Sign in with the client (see tray icon), and add your computer to your developer mesh.

·                     Download Microsoft’s developer SDK (& Tools)

o   Go to https://developer.mesh-ctp.com/Developers/Developers.aspx

o   Then, in your Visual Studio projects, reference Microsoft.Web.dll and Microsoft.LiveFx.ResourceModel.dll. These DLLs can be found in “C:\Program Files (x86)\Microsoft SDKs\Live Framework\v0.91\API Toolkits\.Net Library”. Do NOT add a reference for Microsoft.LiveFx.Client.dll as my Wintellect.LiveFx.dll is a replacement for this library.

o   For some projects, you will also need to add System.ServiceModel.Web.dll (included with the normal .NET Framework).

Some words about building you code with my Wintellect.LiveFx.dll library:

·                     I produced my library because I wanted a lightweight, simple, stateless, and RESTful API for programming against the Live Framework. Microsoft’s Microsoft.LiveFx.Client.dll is stateful, does not allow multiple asynchronous operations to execute concurrently and is not in keeping with the RESTful nature of the Live Framework itself. Microsoft and I have been communicating about this and they have plans to change their API and possibly adopt my API directly or something like it.

·                     My library can be used for all kinds of rich .NET applications including Console, Window Forms, Windows Presentation Foundation, ASP.NET, WCF, etc. At this time, my library will not work with Silverlight due to limitations of Silverlight’s HttpWebRequest class (for example, it only supports GET & POST methods and I need PUT & DELETE too). I am monitoring this closely and fully expect to bring my library to Silverlight in the future.

·                     Since my Wintellect.LiveFx.dll library offers and implements many asynchronous operations, it depends on Wintellect’s Power Threading library (Wintellect.Threading.dll). In fact, if you start accessing the Live Framework asynchronously, then you may also find your own code benefitting greatly from the classes contained inside my Power Threading library. The Power Threading library can be downloaded from http://Wintellect.com/PowerThreading.aspx and there is a separate Yahoo news group available that supports this library: http://tech.groups.yahoo.com/group/PowerThreading/.

An introduction to libraries and type for programming against the Live Framework:

·                     The Live Framework uses a RESTful model where applications make HTTP POST (create), GET (read), PUT (update), & DELETE (delete) operations against the Live Framework servers in the cloud or against a local (or client machine installed) Live Framework “server”. The information interchanged using the AtomPub protocol.

·                     The Microsoft.Web.dll (included with the Live Framework SDK) contains types for low-level AtomPub data processing, serialization, and deserialization. For most people, this is too painful a level to program at.

·                     The Microsoft.LiveFx.ResourceModel.dll (also included with the Live Framework SDK) contains types that mirror the Resources that the cloud/client Live Framework “servers” expose. You should think of the classes defined in this DLL as being data containers. That is, they mostly contain properties. There are some methods that deserialize the wire-protocol text to an instance of a .NET type and there are also methods that serialize an instance of a .NET type to the wire-protocol text required by AtomPub. Effectively, the .NET types provide developers with IntelliSense support while writing code and also compile-time type-safety when using the properties.

·                     The Wintellect.Net.HttpRestClient class (provided by my Wintellect.LiveFx.dll) is a class that simplifies communication with any REST server. This class is not specific to Microsoft’s Live Framework at all. In essence, each method on the class internally does the following:

o   Creates an HttpWebRequest

o   Initializes the HTTP method and headers (which can have some specified defaults)

o   Initiates a Create/Read/Update/Delete request & sends a payload synchronously or asynchronously

o   Returns the HttpWebResponse

·                     Note that the state of an HttpRestClient object can change immediately after a request has been initiated; there is no need to wait for a response. This allows a single HttpRestClient object to be used for multiple asynchronous operations that execute concurrently. However, a single HttpRestClient object should not be used by multiple threads at the same time without performing your own thread synchronization. If you want to have multiple threads concurrently accessing a REST server, then create multiple HttpRestClient objects (they are very lightweight in terms of resource consumption).

·                     The Wintellet.LiveFx.LiveFxClient class (also provided by my Wintellect.LiveFx.dll) is derived from HttpRestClient. The LiveFxClient class is specific to Microsoft’s Live Framework. This class knows about Base Uris and authorization tokens. This class also knows how to perform CRUD operations while converting the wire-protocol data to an instance of a resource class and vice versa.

·                     The Wintellet.LiveFx.LiveFxExtensions class (also provided by my Wintellect.LiveFx.dll) is a static class (and therefore has no state). This class defines a bunch of methods that extend the resource classes defined in the Microsoft.LiveFx.ResourceModel.dll. These methods add the behavior to the data, so to speak. In effect, the extension methods, offer IntelliSense thereby suggesting what actions can be performed on a resource and what additional arguments you must pass in order to perform the action. You must always pass a LiveFxClient object as this contains the default request information (like authorization). Most of the extension methods return a deserialized resource or resource collection. If you desire, you can call HttpRestClient’s SveNextRequestResponse method and/or its SetNextRequestQuery method before making a request to store the HTTP response code/headers in a HttpRestClientResponse object or to set query filter information.

The sample applications:

·                     The LiveFxPatterns project is a console application that demonstrates how to perform various synchronous and asynchronous operations against Microsoft’s Live Framework using my Power Live Framework library. The operations include:

o   Creating mesh objects, data feeds, and data entries (with and without media resources),

o   Creating a directory structure with folders & files visible via the Live desktop (running in a browser)

o   How to update a data entry.

o   How to use query operators when reading resource data.

o   How to add your own custom links to a resource.

o   How to add and read custom data associated with a resource.

o   How to map a mesh object to a device.

o   How to invite a member to a mesh object.

o   How to create a custom news item.

o   How to subscribe to a resource and process change notifications for it.

·                     The LiveFxBrowser project is a Windows Presentation Foundation application that shows you the contents of a user’s Mesh using a tree hierarchy which allows for easy navigation. When you select a node in the tree, you get a window showing you the contents of the selected resource. The view is “cooked” to show you the data in a human readable format: simple data is shown first, followed by collections, followed by link Uris. If you prefer, you can see the same information in raw wire-protocol format (XML, RSS, Atom, or JSON). I've included a screen shot showing the “cooked” view of the data as an attachment.

·                     I am working with Wintellect’s own Andy Hopper to produce a real Live Framework application called “Wintellect Cloudboard.” This application allows you to copy and paste clipboard items to your mesh effectively putting them in the cloud (see how we got the name?). You can then invite others to your Cloudboard and share each other’s clipboard items. You will also receive notifications when new items appear in the Cloudboard. We have set up yet another Yahoo news group for this application (http://tech.groups.yahoo.com/group/Cloudboard/) and I encourage you to subscribe to it if you’d like to be notified when the application becomes available. Our goal is to eventually share the code for Cloudboard and discuss our programming efforts it in articles.

I posted a new version of my Power Threading Library today on http://Wintellect.com/PowerThreading.aspx

This version has some minor bug fixes and a few new (minor) classes. See the Power Threading Overview.pdf file for change log information.

I have recently been spending a great deal of time writing code that communicated with RESTful services (Microsoft's Live Framework, in particular). Towards this end, I'm using the HttpWebRequest class to communicate and, for scalability and responsivenss, I want to perform my I/O operations asynchronously. This has caused me to look into the [Begin]GetRequestStream methods. At first it seemed quite odd to me that there would be a need to get the request stream asynchronously. Afterall, getting the stream just didn't seem like an I/O operation to me. However, via experimentation, I did notice that acquiring the stream did cause some I/O operations. This led me to start some communication with people at Microsoft to really get to the bottom of what is happenning. The information they shared was certainly news to me and I have never seen it documented anywhere. And so now, I'd like to share this information with you too as I think it is very useful for anyone using the HttpWebRequest class to send request data.

There are basically 3 ways to make an HTTP request that contains a payload:

  1. If the payload is amll, you can call [Begin]GetRequestStream and it will immediately return a memory-backed stream that buffers the request payload. Then, when you call [Begin]GetResponse, the HttpWebRequest object calculates the ContentLength header based on how much data was written to the stream and then it initiates the I/O.
  2. If the payload is large (2GB, for example), then you shouldn't cache the whole payload in memory before sending it. In this case, you'd set the ContentLength property explicitly to the payload size. Then when you calll [Begin]GetRequestStream, it now performs all of the I/O up to the point of sending the payload. You now write your payload to the stream which now sends its directly to the network (it does not get sent to an in-memory stream). When you call [Begin]GetResponse, it checks that the amount of data sent matches what you specified for the ContentLength property and does no additional I/O in order to start receiving the response.
  3. If the payload is potentially large, generated at runtime, and you don't know the its size ahead of time then you set HttpWebRequest's SendChunked property to true (and do not set the ContentLength property). When you call [Begin]GetRequestStream, all of the I/O is performed up to the point of sending the payload data (including a "Trasnsfer-Encoding: Chunked" header). You now write to the stream in chunks and these writes go directly to the network. When you close the stream, a special terminating chunk is sent to notify the server that the payload is done. When you call [Begin]GetResponse, no I/O is performed and you can start receiving the response.

I hope you find this as useful as I did. Now, I can make intelligent decisions about my payload data, its size, how to buffer it, how to set headers, and when I can perform I/O synchronously as opposed to asynchronously. I really feel empowered with this knowledge.

Did you know that SharePoint was Microsoft’s fastest growing $1 billion business ever? Well, you probably knew something like that because you’re probably doing SharePoint development. We’re really happy at Wintellect that we are now offering world class SharePoint training that covers both people new to SharePoint to those that want to take SharePoint even farther than ever. Here’s the classes we are offering:

 

The Great SharePoint Adventure
An intense exploration of developing and with all aspects of Windows SharePoint Services (WSS) and Microsoft Office SharePoint Server (MOSS) including Forms, Services, and Report Center.

 

Developing Solutions with SharePoint Server 2007
Learn the development opportunities with Microsoft’s most recent release of SharePoint Products and Technologies covering both Windows SharePoint Services 3.0 (WSS) and Microsoft Office SharePoint Services (MOSS).

 

Inside Windows SharePoint Services 3.0
Explores design and development techniques used when building business solutions with Windows SharePoint Services 3.0 (WSS).

 

All the classes are taught by Marc Gusmano, a Microsoft Regional Director and, obviously, a SharePoint expert.

In February 2009, China is having its very first .NET conference in Shanghai and I am extremely honoured that the conference organisers asked me to participate. I will be givng the keynote talk on .NET performance and a talk on writing responsive and scalable software. In addition, I'll also be on the panel for an open forum discussion. For more information, see the official conference web site: www.softcompass.com. Since the website is in Chinese, I can't understand it myself but at least I recognize my picture<g>.

 I just love China and I look forward to metting and interacting with members of the .NET community there.

Later this month, I'll be doing a geekSpeak webcast. You can find more information here: http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032400477&EventCategory=4&culture=en-US&CountryCode=US

I hope you'll join me.

The title says it all.

Check out the video here: http://channel9.msdn.com/posts/Charles/Jeffrey-Richter-and-his-AsyncEnumerator/

You can download the code here: http://Wintellect.com/PowerThreading.aspx

You can join the Yahoo Group for support here: http://tech.groups.yahoo.com/group/PowerThreading/

The latest version of Jeffrey Richter’s free Power Threading Library, which includes a DLL for use by Silverlight applications and components is now available for download. The Silverlight version includes Jeffrey’s popular AsyncEnumerator class that allows developers to use a synchronous programming model while performing asynchronous operations. This allows developers to create very fast and responsive applications while using very few threads. To learn more click here. To download the library click here.
Well, I'm back from my concert tour in England. I had just a spectacular time and made some good friends. The last show, in Birmingham, was recored by the BBC and is available for listening on the BBC's website this week. If you like to hear a concert (where I helped set up the instruments & equipment), then go here: http://www.bbc.co.uk/radio3/ and scroll down until you find Django Bates. Django's version of "In the Mood" is particulaly awesome and is not available on any of his albums. I hope you enjoy!

I don't normally blog about personal things but I'm just so excited about this one that I had to. I am pretty passionate about the music I like and I like a lot of jazz- fusion/rock stuff. In the 1980's I was into Bill Bruford's Earthworks jazz group (some of you might know Bruford from 1970s Yes and King Crimson). At this time, Earthworks had a keyboardist/horn player named Django Bates with him. I really liked Django's style and over the past 20 years or so, he has put out a number of jazz CDs. I have purchased all of them and I love them all. In June 2008, Django put out his most-recent album, Spring Is Here (Shall We Dance?), and I just love it! It has 19 musicians on it all playing very complex music with a bit of that dry British humor that I love so much.

I checked Django's web site (http://DjangoBates.co.uk) and discovered that he and his band are playing some dates in England; they would never fly to the United States because the expenses of flying 19 musicians over would be too cost prohibitive and Django's music doesn't appeal to the mass public so it's unlikely that he would recover the costs. So, I decided that I would fly out to London to see the show. But then, I had an idea...

I contacted Django (via MySpace) and his manager and told them what I was planning to do and explained to them that instead of flying out there, I'd give them the money to video tape the concert and send me a video; then they could sell the video to other fans if they wanted to. It seemed like a win-win situation to me as now I could stay home and not miss days of work and I'd also have a video of the show which I could watch repeatedly.

Well, one thing led to another during the e-mail exchanges and Django's manager invited me to go on tour with the band! So now, I'm flying to England and I'm attending all 3 shows on October 15, 16, and 17. I'm helping the band set up for each show and I'm riding with them on their tour bus as we go from London to Manchester to Birmingham! This is a great opportunity for me and, as I've said, I'm so excited that I just wanted to share it.

If anyone reading this also happens to be going to any of these concerts (see Django's web site for dates/locations), drop me a line and we can meet up at the show.

Or, if you get a chance, check out some of Django's music - I love it!

I am presenting at Wintellect’s Devscovery conference this week. At this conference, the attendees are able to set up 1-on-1 sessions with any of the speakers. One attendees wanted to ask me some questions about my Power Threading’s AsyncEnumerator class. They were using this class in a Windows Form project of theirs and I thought it would be best if I discussed what is going on in this forum.

In .NET 2.0, the CLR team added a System.Threading.SynchronizationContext class. This class provides a way for an application model (like Windows Forms, WPF, or ASP.NET) to describe its threading model (such as how to marshal work to a Windows Forms/WPF GUI thread). My AsyncEnumerator class takes advantage of this automatically so that iterator code executes on the GUI thread for Windows Forms and WPF apps. For ASP.NET, this allows my AsyncEnumerator to associate the client’s culture and IPrincipal information to thread pool thread that will eventually call into your iterator code.

When you construct an AsyncEnumerator, its constructor grabs a reference to the SynchronizationConext-derived object associated with the calling thread and saves this reference in a private field. Then, whenever my AsyncEnumerator calls into your iterator, it always does this via the SynchronizationContext-derived object. For Windows Forms/WPF, this means that your iterator gets invoked by queuing a request on your GUI thread’s message queue. This means, that your GUI thread MUST pump messages in order for your iterator to execute its code. The Devscovery attendee was calling AsyncEnumerator’s Execute method (instead of the preferred BeginExecute method) from their application’s GUI thread. The Execute method blocks until the iterator completes running and since this method was called form the GUI thread, the iterator was unable to run and so a deadlock occurred.

This behavior is by-design as the whole purpose of the AsyncEnumerator is to execute code asynchronously and, in a GUI application, to keep the UI responsive. In fact, I always discourage calling Execute at all. The only reason why the AsyncEnumerator even offers the Execute method is for testing or to demonstrate functionality.

However, I’d also like to point out that the AsyncEnumerator offers a SyncContext property and so, the Windows Forms/WPF developer can construct an AsyncEnumerator and then set its SyncContext property to null before calling Execute. This will allow thread pool threads (as opposed to the GUI thread) to call into your iterator – just make sure the code in your iterator doesn’t try to update any GUI controls.

Finally,  I’d like to point out that an iterator can change its AsyncEnumerator’s SyncContext property within the iterator itself. This can be useful if you have some code in the iterator that can be run on any kind of thread and some code that must be run on the GUI thread (to update UI controls). In fact, in order to support this better, I’ve added a feature to the August 20th, 2008 version of the library. With this new version, within an iterator, you can change the SyncContext property and execute a “yield return 0”.  When you do this, I will internally call ThreadPool.QueueUserWorkItem to have a thread pool thread continue your iterator. However, the thread pool thread will execute your iterator via the current SyncContext property.  Another user wanted this feature so that they could improve the performance of their iterator code where some code needs to update the GUI and some other code needs to just do some compute-bound work (which doesn’t have to be on the GUI thread).

I have set up a Yahoo group for people interested in using my Power Threading Library. Currently, the group is public so anyone can join. I am the moderator of the group and so I can answer questions, offer comments/suggestions on the library's use, and address and bugs or feature requests. I will also make new version announcements via the group as well.

Here is the group information:

Library Link: http://wintellect.com/PowerThreading.aspx
Group link:   http://tech.groups.yahoo.com/group/PowerThreading/

Post message: PowerThreading@yahoogroups.com
Subscribe:       PowerThreading-subscribe@yahoogroups.com
Unsubscribe:    PowerThreading-unsubscribe@yahoogroups.com

I look forward to meeting all of you in the group.

At the April 2008 Devscovery (http://www.Devscovery.com) event in New York, I recently did a new talk entitled "The Performance of Everyday Things". The talk is about the performance of using everyday constructs in .NET/C# such as method calls, arrays, loops, garbage collection, and much more. I will be repeating this popular talk at the Redmond, WA Devscovery event in August 2008.

 After the talk April presentation, I did a small interview related to this topic. The interview can be found here: http://getpixel8ed.com/shows/everything

More Posts Next page »