Monthly Archives: April 2006

You are browsing the site archives by month.

What’s wrong with MSDN documentation?

A large part of my job at Microsoft is to provide developers with the knowledge they need to make use of the IIS 7.0 SDK.  While the information about IIS 7.0 is not out yet for review, there are plenty of docs provided in other areas, such as the .NET Framework SDK and ASP.NET sections, which can be used as a benchmark.   In order to make the IIS 7.0 SDK a success, we must do more than just put out a good product. We must also describe how to use it properly or it just will not be used.  So I pose a question to anyone who has ever looked something up in MSDN, what is wrong with the documentation you have used so far?  What is good about it?  What would you like to see to a greater/lesser extent in our documentation?   Feel free to flame us, or praise us.  If you have suggestions, comments, or ideas, feel free to express them here.

Your feedback will help me understand how to increase your satisfaction with MSDN and Microsoft in general.

Or better yet, if you have some desire to play with new technology that isn’t documented yet and provide that content to a worldwide audience, why not apply

Protests in Seattle: anti-communist?

The news has been reporting about China’s President Hu visiting Seattle, its businesses and, of course, Bill Gates’ home. What wasn’t widely publicised was the number of protesters in the area. Monday night, I had to run back up to my office and grab some paperwork I left in my desk. On my way up there, I saw several protesters at the corner of 40th and 156th in Redmond. Their banners decried alleged ill treatment of Falun Gong supporters, and, of all things, communism. Having only been in the Puget Sound area for a short while, I find myself wondering how this can be. They don’t call this side of the continental US the ‘left coast’ for nothing. That puts us square in the center of the pro-socialism crowd. So again, I ask, what are these people complaining about? This is what this side of the country yearns for — complete government control over what you can and can’t say at what time, in the presence of what company and with what tone. If government were a drug and communism were crack, socialism would definitely be cocain — the perfect gatway drug to ease you into the rest of your useless life as a crack adict. So I say, put your banners down and bring peace to this riddled puget sound area. Quit rocking my boat! The government of China knows what is best for their people and has every right to tell people what they can and cannot do with their money, their children, their weapons, and, of course, their voice. And don’t you worry with programs like social security, medicare, medicaid, welfair, unemployment, national endowment for the arts, Department of Education, FCC, minimum wage, income tax, tarrifs, gas taxes, sin taxes and the like, you will never have to worry about forming your own opinions on what is an appropriate income at retirement, what drugs are best for you, being responsible at work, painting something that someone is willing to pay to look at, what your children are and are not allowed to learn, what your radio DJs are and are not allowed to say, how much crack a single mother of four can afford to buy while holding down a part time job at McDonalds, how much you are allowed to earn for yourself, what you are allowed to buy from other countries, where you can afford to travel, or what habits infringe on another person’s rights so much that you have to pay extra for the right to continue it. Isn’t socialism fun?

Live from Redmond

A little over a year ago, I emailed Steve Ballmer at Microsoft directly about an idea to make a digital, online user group community. I wanted to be able to let user groups from across the country make their monthly presentations available via the web. Rather than being limited to what is available in local communities across the country, I thought it would be very beneficial to be able to watch any presentation at any user group on any given month: Community-created web-casts if you will. I was suprised to hear a response from Mr Ballmer direclty. I still have the email in my inbox because it reminds me just how much Microsoft DOES care — even the biggest guys in the company will handle customer-related issues. Mr Ballmer thought it was a great idea and gave me some contacts to discuss with INETA as well as several other groups. To be honest, I got way too involved with other things and sadly never followed up. Apparently, the idea wasn’t lost on the folks at INETA or MS though. Brad Abrams has just reported that this dream is close to a reality in a new offering called “Live From Redmond.”. Although it is not quite the community I was envisioning, it does at least make many user-group meetings available via live meeting. It’s a very exciting concept and I hope you’ll take advantage of it.

Threading issue with VB.NET Default Instances

Here is an issue that showed up for one of our customers in the Microsoft forums for Visual Basic .NET.  It is NOT the typical ”cross-threaded UI update” issue that you might think. No, this one, IMO, is slightly harder to catch since no exception is thrown to let you know something has gone wrong.

One of the many new features of Visual Basic .NET are default form instances.  As the feature lists explain, a default form instance prevents you from having to “new up” an instance of a form before acting on it.  So, instead of using:

Dim frm As New frmMain
frm.Show()

I can simply use:

frmMain.Show()

This is handy, particularly for the folks coming from VB6 who are used to forms that behave in this manner.  However, default instances present a very interesting problem.

Take, for instance, a project that I create with a form (named frmMain) and a module (named BackgroundMethods.vb) .  For the form, I have simply added a multi-line text box (named txtOutput) and a button control (named button1). 

Here is the code I have in my project:

[frmMain]

Imports System.Threading
Public Class frmMain
  Private Sub Button1_Click( ByVal sender As System.Object, _
                             ByVal e As System.EventArgs) _
                             Handles Button1.Click
     Dim t As Thread = New Thread(AddressOf GetData)
     t.Start()
     txtOutput.Text &= "Updates complete"
     ' Break after the call above to read the value
     ' in txtOutput.Text
  End Sub
End Class

[BackgroundMethods.vb]

Imports System.Threading
Module BackgroundMethods
   Public Sub GetData()
      WaitForData("Message 1")
      WaitForData("Message 2")
   End Sub
   Public Sub WaitForData(ByVal strMessage As String)
      ' Presumably this method would actually be
      ' waiting for data from a network connection,<
      ' serial port, or other source
      Thread.Sleep(2000)
      My.Forms.frmMain.txtOutput.Text &= (vbCrLf & Now().ToShortTimeString() & _
      vbTab & strMessage)
      ' Break after the call above to read the value
      ' in My.Forms.frmMain.txtOutput.Text
   End Sub
End Module

So the simple example is that I have a button which, when clicked, will execute the “GetData” method asynchronously in a module.  That method is going to call the WaitForData method that updates the UI with two different messages (“message1″ and “message2″).  WaitForData is supposed to simulate a long-running process, so I threw in the typical “thread.sleep” call to make this illusion. 

If you run this code, you will notice that no exceptions are thrown, but the UI for your form is also not updated.  Why is this?  You would have at least expected a cross-thread exception, right?

In any other managed language, this likely wouldn’t happen — namely because the “My” application is specific to VB, as well as default form instances!  In C#, if I try to update the UI from another thread, I would get an exception stating: “Cross-thread operation not valid: Control ‘txtSerialIn’ accessed from a thread other than the thread it was created on.” which could be solved by using the “Invoke” method.   

The issue with Visual Basic, in this instance, is that the default form instances are thread-specific.  So, when I try to access the form using My.Forms.frmMain from within the worker thread, a NEW default instance is created under the covers.  My calls to update the text box are then executed on the NEW instance of the form which resides in the same thread as the call to update it — hence it doesn’t throw a cross-thread exception. In the mind of the VB program, the request to update the textbox occurred without an error.  When the worker thread dies, the second instance of the form (which was never displayed) is now a candidate for garbage collection.  Meanwhile, back on the original thread and original form the textbox is left blank.  You can validate this by running the program (I have attached sample code to this blog post) and setting breakpoints on the textbox update line in the WaitForData method, and in the last line of the button1_click event handler of the code.  You will notice that after the second call to WaitForData (before the debugger exits the Sub) that My.Forms.frmMain.txtOutput.Text has been properly set to the value you expected.  However, remember that this is on a second background instance of the form, not the original one you expected.  Once the debugger hits the last line in the button1_click event handler, read the value of txtOutput.Text and realize THAT instance of the textbox was never updated.

So what is the solution?

First off, you still have to use the “Invoke solution” that is often times bandied about in threading discussions.  To do this in VB.NET (and particularly in our solution), do the following:

1. Add the following code to the top of your BackgroundMethods.vb file:

Delegate Sub UpdateTextHandler(ByVal strMessage As String

This allows you to create a delegate that can be invoked on the UI.

2. Add the following method to your frmMain file:

Public Sub UpdateTextMethod(ByVal strMessage As String)
   txtOutput.Text &= (vbCrLf & Now().ToShortTimeString() & vbTab & strMessage)
End Sub

This creates the method that will actually be executed via your delegate from the worker thread.

3. Change your WaitForData method as follows:

Public Sub WaitForData(ByVal strMessage As String)
    ' Presumably this method would actually be
    ' waiting for data from a network connection
    ' serial port, or other source
    Thread.Sleep(2000)
    Dim f As frmMain = My.Application.OpenForms("frmMain")
    f.Invoke(New UpdateTextHandler(AddressOf f.UpdateTextMethod), _
             New Object() {strMessage})
End Sub

This method now uses the form’s “Invoke” method (actually defined in Control) to execute UpdateTextMethod on the original form via the UpdateTextHandler delegate.

So what is happening is that your new thread is getting an instance to the existing frmMain instance by going through the OpenForms call.  Once I have that instance, I can invoke a delegate that points to the “UpdateTextMethod” of the existing form ( passing in the message in the object array ).  By invoking, I am able to get back on the UI’s thread and that call can execute any updates to the UI that it wishes.

Keep this in mind the next time you are not receiving errors and your UI isn’t getting updated how you would expect — particularly if you code communicates with the network, a serial device, or other device which communicates asynchronously.

What does it take to get a Microsoft MVP?

As many of you know, I received a Microsoft MVP award this year for C#. I’ve been asked a few times what makes an MVP — despite there being several pieces of information available to answer that question, I thought I’d answer it quickly myself.


There is no set formula for gaining an MVP. Some do it by participating in online communities such as forums, newsgroups, and other such public stomping grounds for technological communication. Some people do it by writing books, printed magazine articles, blog posts, or online articles. Some folks have obtained their MVP by simply participating in local community events, helping out in whatever way is necessary to make user groups, code camps, MSDN events, and the like go off without a hitch.


By participating in communities, I mean that you answer questions clearly, honestly, and completely — not simply respond to every post hoping to get a post count high enough to get noticed. You have to actually earn some respect in the community for having answers — not for posting useless information.


The same can go for blogs. Simply pointing to other sites or blog posts from yours — effectively becoming a technology aggregator — doesn’t work either. Have some original content. One method that is quite useful is to combine your community participation with your blogging. Instead of simply answering a question in a forum, try to write a coherent blog post about the issue, and then point the user in the forum to your blog post. Now, the question and the answer are made available to everyone in the forums as well as on your blog!


Another good idea is to take that same topic, and then use your solution as the topic for a user group meeting. Many user group meetings in smaller towns are in great need of speakers — either at the meetings themselves, or at Code Camps. Help them out by sharing what you’ve learned with the local community. Furthermore, find out who the Microsoft Developer Evangelists are in your area and see if there is anything they need help with at upcoming events. Being valuable to Microsoft is the whole point of the “V” in MVP. Helping your developer evangelists definitely adds value and will help get you on the radar screen if you persist for a good deal of time.


As you can see, you can solidify yourself as a subject matter expert quickly by studying one area and using that same information in blogs, forums, and user groups. It wouldn’t hurt to expand on those topics by contacting online article sites or even printed mags to see if they have an interest in your topic. As you can guess, a little effort can go a long way.


I don’t really know how I received mine other than some of the ways that I described. I wrote four books on .NET topics, participated in local and regional events, communicated with regional directors, developer evangelists, and community champions to find out what was needed to drive participation locally. I blogged, answered a few forum posts, and worked with Microsoft Learning to develop the new generation of certification exams and supporting eLearning workshops. Find your own mix and figure out what works for you, and what doesn’t. Don’t rely on the company you work for to get you there. MVP is an individual award and it depends on YOUR commitment and reputation , not the reputation or commitment of the company you work for — in many instances, that’s a plus for you!


This posting is provided “AS IS” with no warranties, and confers no rights. The content of this site are my own personal opinions and do not represent my employer’s view in anyway. In addition, my thoughts and opinions often change, and as a weblog is intended to provide a semi-permanent point in time snapshot you should not consider out of date posts to reflect my current thoughts and opinions.

Free Book: Microsoft VB.NET 2005 for Developers

Microsoft has a free book available for download for anyone who wants it.  Download the whole book, or download it chapter-by-chapter (8 in all).  Check it out at http://msdn.microsoft.com/vbasic/learning/introtovb2005/

Debugging Resources

It is my opinion that the difference between good developers and outstanding ones are the way that they debug applications. As such, I wanted to point you to some great debugging resources to get you well on your way to standing with the outstanding developers.

First off, there is the issue of understanding Windows to begin with that get a lot of people in trouble.  Many issues can be traced down to something that is “working as designed”. As such, I highly recommend the Microsoft Windows Internals book from MS Press.  This book will give you a great understanding of how Windows works.  Next, I would brush up on .NET debugging skills. To do so,  I recommend a .NET 2003 book, but most of the debugging skills still apply to 2005, so don’t be dismayed by the title: Debugging Applications for Microsoft .NET and Windows. Once again, John Robbins from Wintellect writes one awesome book.

Well, books are great, but what about free resources?  I have some of those too!

First, you can check out the windows debugging website at:
http://www.microsoft.com/whdc/devtools/debugging/default.mspx

Then there are a new series of webcasts that have just been released in the past week or so dealing with the very issue of debugging:

TechNet Webcast: Microsoft.com Operations Introduces Real World Debugging: Determining When You Have a Problem and Beginning the Initial Debugging (Level 300)

TechNet Webcast: Microsoft.com Operations Introduces Real World Debugging: Debugging CLR Internals

TechNet Webcast: Microsoft.com Operations Introduces Real World Debugging: Diagnosing Memory Leaks in ASP.NET Applications (Level 300)

TechNet Webcast: Microsoft.com Operations Introduces Real World Debugging: How to Tackle Problems in Dynamically Generated Assemblies (Level 300)

TechNet Webcast: Microsoft.com Operations Introduces Real World Debugging: Debugging Without the Debugger in IIS and ASP.NET (Level 300)

OK. So maybe I did not have a TON of debugging resources, but this is a great start for anyone who wants to make himself or herself into an outstanding SDE or SDET. So go work yourself into a “debugging guru”.  By the time you are done, hopefully John Robbins’ new book on debugging will be out.

202 VB.NET Samples

I just wanted to bring some attention to a resource that I think is extremely valuable for VB developers (and really, any .NET developer using any other language for that matter).  MSDN has a website with 101 Code Samples for VB.NET 2005.  There is also another website for those of you that haven’t upgraded to 2005 yet: 101 Code Samples for VB.NET 2003.  Both of these sites have very valuable sample code for doing things such as network programming, using regular expressions, executing transactions, handling/changing ACL’s on files, accessing data, performing bulk data transactions, executing asynchronous operations (one of my favorite topics), using ClickOnce, creating ASP.NET pages and more!  It is a great resource for those of you that just want to get it done and don’t want to waste a lot of time reading specifications on each class in System.Net or System.Data.  The samples are robust and provide some great starting points for anyone interested in the many topics available in these samples.  Check them out and let me know what you think!

XBOX 360

On my way home from work Friday, I stopped by a local game store had a few 360 consoles in stock.  This just a short time after it was announced that shipments would be stepping up for the console. So, I bought myself a premium console and headed over to the Microsoft store and bought Kameo.  I then headed home with a giddy little grin on my face.  On the way home, I stopped at yet another game store and bought Ghost Recon and Fight Night. 

When I got home, I started feverishly hooking the console up.  I realized quickly that I didn’t have enough power outlets at my entertainment center to plug in the 360 so I started running around the house looking for a power strip to plug all of my other devices into (the 360 should not be plugged into a surge protector).  Since we  JUST moved to the Northwest  all of our stuff is still mostly packed in boxes. I had paper and cardboard flying everywhere while looking for this strip! At last: I found one!  “I’ll clean up the mess later,” I thought as I rushed back into the living room to finish the setup.
I turned the console on and changed the television to channel 3 and then 4 — an obvious habit I had from the last console I owned so many years ago (Nintendo — nope, not 64, not DS — just plain old Nintendo).  I finally got everything set up right and then I saw it — the Xbox 360 console — right there on my TV.  I could curl up to this thing at night for warmth — I’m sure of it.

I’ve already been playing so much longer than I ever expected.  I’ve already got a list of friends hooked up in my console and have already played a few rounds (and lost many) of Fight Night.  I love this game and I can already tell that I need to apply some time management skills to keep me productive.  If you haven’t played Fight Night yet, let me explain.  This game lets you build your own fighter. You can control his stats, his clothes, his skills and even his look.  That’s right, when you build your fighter, you can control every aspect of his looks — cheek shape / size, skull shape/size, jaw shape/size, eye color/socket size, eye brows, facial hair, and more.  You can then add tattoos to the boxer’s back, arms, and chest.  The amount of customization is unreal.  You can then start fighting and training your boxer up the ranks, all the while fighting great boxers like Ali, Frazier, Leonard, and more.  As you are fighting, the level of control is amazing and the detail in the graphics is fantastic.  I can lean back, block with one arm, two or even duck and cover. The conrol is 100% up to me — no preset motions that limit your ability to create your own fighting style. Jab left then Haymaker right.  Jab high right, jab low and left, jab low left, uppercut right, parry, counter haymaker!  It’s indescribable!  I’m addicted already:  not good yet, but addicted!

I then picked up Ghost Recon and tried playing that.  It’s really amazing how cool this game is, but honestly — it’s a lot harder for me to play this than anything else.  To explain, I’ve been a PC gamer for a while. I’ve played PC-based FPSes (First Person Shooters) since .. well Wolfenstein 3D.  I then moved on to games like Doom (1 and 3), Enemy Territory, Quake (1, 2, 3 4), Call of Duty, and Half Life. I’ve played them as single player. I’ve played them as multiplayer. I played in clans. I created trick jump videos and even got bored and started doing trick jump videos backwards.  Yes — I’m no stranger to FPS gaming. But playing on a console is so much more… contrived.. harder.  In my opinion, the keyboard and mouse are the best controllers for an FPS. None-the-less, the game play itself is awesome.  I also like that being shot actually hurts the character — and being shot in the right spot — even with one shot is fatal.  This is contrary to a lot of older games that I played that just took your ‘health’ down with gun shots to the chest and head.  In any case, once I’ve mastered Fight Night, I’m definitely going to give this game another shot with a controller.  Note to XBOX 360 team — allow mouse and keyboard controller input for games! 

Kameo was … different. I’m not used to playing games like this, and I honestly didn’t put much time into it. The game is very cool looking. Kameo can change shape into a rolling spikey looking creature that can spin at high velocity toward monsters. She can also transform into a plant-like creature that is great at sneaking up on things. She can take the shape of a blue ape-like creature that can bash monsters and stick them to his back and use those monsters as weapons. More shapes are available later. It’s very… umm… interesting. Kameo herself can fly short little hops over obstacles.  This game appeals to my some but for me, I think I’ll stick to the other two for now.

The games themselves aren’t the only thing that are cool.  I can connect my XBOX to my PC’s in the house and use MP3′s I have stored there as well as pictures and movies.  The only thing I wish is that I could continue playing those MP3s while I played Fight Night. I prefer my music to EA sports selection!
This post was much longer than expected. But I couldn’t help but share my enthusiasm about this machine.  For those that have stuck around a bit, I have some thoughts: If you buy one of these systems, consider buying the core system. You’ll save $100 that you can spend on a 20GB  hard drive and a pair of headphones that feel good for you.  The ones included in the premium system aren’t that great and are cheaply made, IMHO.  Once again, I could just be spoiled from my previous online gaming headphones I use. Also, consider buying the wireless ethernet adapter, and some recharge kits for your controler(s).  All of this will cost a bit more, but will make your gaming experience better, IMO.  That’s all for now. Happy gaming!