DevCenter

posts for the MSDN VB Dev Center

RemoveHandler Issues with Custom Events

This is a case of things being more complicated that I thought they should be. Since it took a while to figure this one out, I thought it was worth explaining and putting all of the pieces to the answer in one spot. Let me set the stage. Architecturally, I have the notion of generic producers and consumers. These put items onto, and remove items from, a queue. This provides a generic, thread-safe mechanism to load balance the creation and processing of work items in our application. Part of the IProducer(Of ...

Regular Expressions in Visual Studio “Find”

I had a case today where I wanted to find all the spots within our application that a developer had explicitly set the BackColor property of a control at run-time. As you can imagine, a simple search ended up with my finding a ton of designer code where the generated code was setting the property. (It sure would be nice if Visual Studio would let you exclude comments and designer files from the search – but that’s not in VS2008 or VS2010 Beta 1, unless it’s well hidden in both.) Wildcards seems like ...

Oracle + Azure = Crash and Burn

One of the downsides to Azure is that it’s error messages need a LOT of work. I just installed the July CTP of Azure. After doing so, even the simplest cloud project would fail. I’m talking “Create New Project” then F5… wait 30 seconds… bomb. I kept getting the ubiquitous “Role instances did not start within the time allowed. Please try again. If you continue to encounter this behavior please try shutting down the Development Fabric." message. Nice and descriptive. Digging into the problem, it looked ...

Numeric Chicanery

For those of you who have been around since the VB6 days, you surely remember the interesting rounding behavior of CInt(x). Specifically, it rounded a number ending in .5 to the nearest even number. That is, CInt(2.5) rounded to 2 and CInt(3.5) rounded to 4. This behavior still exists in VB.NET. No real surprise there. And, to be honest, I don’t mind it that much. When I see “CInt,” I really don’t have any preconceived, intuitive understanding of what it does. Math.Round(x) is another question entirely. ...

Microsoft P&P team releases VB support for Composite Application Guidance for WPF and Silverlight (aka "Prism")

One of the places lacking good VB support was the Microsoft Patterns & Practices’ Composite Application Guidance for WPF and Silverlight (formerly code-named "Prism"). The P&P team is now releasing VB versions of the QuickStarts, Hands-On Labs, and How-to Topics! Get all the good stuff here This download is provided to help Visual Basic .NET developers use the Composite Application Library. While Prism is not yet 100% VB, this is a big step in the right direction. The VB code was reviewed ...

Deploying WCF Services to Azure

My past experience with WCF services has followed a slightly unusual path. For a variety of reasons, most of the services I've written have consisted of an interface and an implementation. Pretty straight-forward thus far. However, where it gets a little unusual is in the hosting mechanism. We're using Windows services to host of WCF services. This works out well for us, since these services live on intranets, and aren't publicly exposed. When looking at Azure, services are a little different. It's ...

The Developer's Way to Convert Code

All right, all you developers out there... let's see a show of hands. How many of you delight in finding new ways to solve a problem? You. Yes, you in the back. Get your hand up. You can't call yourself a developer if you don't enjoy finding a new (preferably somewhat convoluted) to solve a problem. I've been doing some work that involves converting C# code to VB.NET code. I was sitting in the speaker lounge at VS Live, shortly after getting into San Francisco. I'd played a little bit on the plane ...

Using Exception Handling to Retry an Operation

I got the following question via e-mail: I want to catch timeout errors when I execute a script. Catching the error is easy, but I then want to retry 3 times. In VB6 I could just resume a command when I caught the error. How can I do this with vb 2008 using try..catch? This is a case where two different techniques come into play. The first is using a number of Catch statements to allow you to catch specific types of exceptions. The second is to make essentially a recursive call to the function, with ...

Try/Catch Performance

I'm really not obsessed with performance -- honest! However, when a co-worker asked me today exception handling was an acceptable way of coding defensively, my reaction was rather predictable. Exceptions are pure evil, and should be... well, exceptional. Yes, you guessed it. The next question was "How bad is try/catch really?" The short answer is that is involves minimal overhead... unless an exception is thrown. In that case, the .NET exception handling mechanism does a few nice things, like providing ...

VB.NET Generics with Multiple Constraints

I had a case today where I needed -- well, wanted -- to implement a generic class that was a little... unusual. Essentially, I'm working on a queuing mechanism based on Joe Duffy's BlockingBoundedQueue(Of T). Mind you, unlike Joe's sample, mine is written in VB.NET. ;) Taking it a bit further, I created a wrapper that specifies the number of producers and consumers of queued objects, as well as the queue capacity. Since I'm going to be turning this over to a bunch of developers to play with, I also ...