• Eric Gunnerson's Compendium

    MC Hawking


    Little known fact of the day...

    Noted Physicist Stephen Hawking also has a career as a dope MC

  • Eric Gunnerson's Compendium

    Eric Sink relates to the "Software Legends" marketing campaign by putting up his own site...
  • Eric Gunnerson's Compendium

    C# Column: Web Services, Remoting, and PocketPC


    My most recent C# column has gone live on MSDN. In it, I talk about what I learned in trying to build a remote control application that runs on the PocketPC using the compact framework.

    If you have comments on the column, please enter them, and I'll be sure to respond.

  • Eric Gunnerson's Compendium

    Higher Primates Can Program


    This came to me from one of the members of the VB team.

  • Eric Gunnerson's Compendium

    Who said this?


    I was listening to something a day or so ago, and I came across one of my favorite:

    Supreme executive power derives from a mandate of the masses, not from some farcical aquatic ceremony.

    Who said this, and who did he say it to?

    If you don't know the answer, then I despair at the quality of your education. Look at the comments, where I'm sure somebody will post the answer.

  • Eric Gunnerson's Compendium

    Forms, threading, and frustration


    I have a fair amount of windows forms code that uses multiple threads. Because of the way that Windows handles its user interface, you should only be updating the user interface from the main thread. If you try to do it on other threads, bad things happen, and they can be pretty hard to track down.

    Windows forms includes some code to detect when that is happening, but it can't do it in all cases. Well, it could, but if it did, the perf would be pretty atrocious.

    When you get in this situation, you need to call Invoke() on the form, and pass it a delegate to the function that you want to be called on the main thread. In my case, I need to do an update to my form text when I get an event from the other thread. My code looks something like this:

                    // setup code
                object.RemoteUpdate += new UpdateHandler(RemoteUpdateFunc); 
            public void RemoteUpdateFunc2(object sender, RemoteUpdateEventArgs args) 
                // use the values here. 
            public void RemoteUpdateFunc(object sender, RemoteUpdateEventArgs args) 
                this.Invoke(new UpdateHandler(RemoteUpdateFunc2), new object[]
            {sender, args}); 

    I have to create a separate function just to do the forwarding, and I have to do that for every event that I want to hook to. That's a lot of boilerplate code that I don't want to write.

    So, I set out to try to create a class that could wrap the object. Here's the class that I wrote:

      	public class Invoker
    		Delegate d;
    		Form form;
    		public Invoker(Form form, Delegate d)
    			this.d = d;
    			this.form = form;
    		public Delegate Handler
    				return Delegate.CreateDelegate(d.GetType(), this, "Dispatcher");
    		public void Dispatcher(object sender, EventArgs args)
    			form.Invoke(d, new object[] { sender, args });

    The goal would be to write code like this:

               Invoker invoker = new Invoker(this, new UpdateHandler(RemoteUpdateFunc));
               object.RemoteUpdate += (UpdateHandler) invoker.Handler;

    Unfortunately, delegates can only point to methods that are *identical* to the delegate definition. You can't, for example use a delegate that's defined as:

            public delegate void EventHandler(object sender, EventArgs args);

    to point to:

            public delegate void UpdateHandler(object sender, RemoteEventArgs args); 

    even though RemoteEventArgs is derived from EventArgs. So, that means that you can only use this approach to point to delegates that have EventArgs as their second parameter, which doesn't make it very interesting.

    So, I had to abandon this approach. The alternative is to modify the class that I'm using so that it can make the call. I didn't want that class to have to have a reference to the Form class, so I created a delegate like:

            public delegate void InvokeHandler(Delegate d, object[] args);    

    and passed that to my the class that has the events. It can then use the delegate to make the Invoke happen. Not as clean as I had hoped, but it does help a bit.

  • Eric Gunnerson's Compendium

    It's Time for Language Divergence


    In It's Time for Language Divergence, Patrick Meader discusses divergence between C# and VB programmers.

    I agree that VB and C# users have differences between them, but I think that saying that the languages should diverge is a strange position. It's not about divergence, it's about the making sure that VB and C# serve their customers well. If that means language divergence, then that's fine

  • Eric Gunnerson's Compendium

    Disposing, using, and null


    I had an interesting discussion a day or so ago on when you should implement IDisposable on a class. Like many things, it's more complicated when you dig a little. There are three scenarios that are interesting:

    1) A class that wraps an unmanaged resource
    2) A class that has fields that implement IDisposable
    3) A class where no fields implement IDisposable

    The first one is the easy one. Since you are directly responsible for that unmanaged object, you will need to implement a finalizer (written using destructor syntax in C#) to do the cleanup. You will also *probably* want to implement IDisposable, so the user can call Dispose() to clean things up. There's a standard idiom in the docs for doing this.

    In the second case, there is no direct cleanup you need to do, so you shouldn't write a finalizer (what would it do?). If your users will want to clean up early, you may want to implement IDisposable and call Dispose() on your fields from your Dispose() function.

    In the third case, you should do either. If you do implement a finalizer, you will just slow things down.

    Another related question is whether setting fields to null will result in quicker recovery of memory. This was important to do in the VB6 world, but in the .NET world, it rarely does anything. The only time it would help is if there was a variable that held a live reference, but wouldn't drop off the stack for a long time. I think I could construct a loop like that, but I think it's pretty rare.

  • Eric Gunnerson's Compendium

    The Tour gets interesting...


    Yesterday's stage was the best one I've watched in a long time. Lance Armstrong gets attacked, and doesn't blow away the field. Tyler Hamilton rides with Lance despite having a broken collarbone. Jan Ulrich loses 90 seconds to Lance. Iban Mayo does blow away the field.

    All of this in front of thousands of rabid fans.

    Lance ends up in the yellow jersey, but not by much. This is going to be much more interesting than last year.

    Best moment in the coverage was when they showed 3 cows in a pasture, wearing jerseys yellow, green, and spotted.

  • Eric Gunnerson's Compendium

    Socket programming tip: Localhost != local ip address


    I've been writing some socket-based code for an upcoming column, and it worked really nice when I used localhost for the client and server on another machine, but broke when I tried to use the machine name.

    Just something else I didn't know about networks. localhost is not the same thing as the local ip address, but is rather a totally separate address.

    If you want to create a TcpListener, you should use IPAddress.Any as your parameter for the IP address. That will do what you want.

  • Eric Gunnerson's Compendium

    Le Tour 2003 starts


    Le Tour de France 2003 started last weekend. The tour, if you don't know, is a 2000ish-mile, three-week race up and down the mountains in France. It's widely regarded as one of the toughest physical challenges around.

    The best coverage in the US is on OLN.

  • Eric Gunnerson's Compendium

    The Brunching Shuttlecocks site closes


    The offbeat and often insanely funny Brunching Shuttlecocks website has closed. Well, it hasn't actually closed, but they've stopped updating it. The site is still there, with archived content.

    From their wonderful movie reviews, to their offbeat ratings, they've written the kind of comedy I sometimes aspire to write.

    I highly recommend the "The Book of Ratings", which is an assembly of ratings from the site, in portable dead tree format.

  • Eric Gunnerson's Compendium

    Online Slang Dictionary


    The Online Slang Dictionary is a reference everybody needs sometime, especially those of us who find it increasingly hard to appear cool to our 9-year-old daughters.

  • Eric Gunnerson's Compendium

    Regular Expression Workbench V2.0


    I've finished a new version of my Regular Expression Workdbench, and it's now available on gotdotnet. If you use regular expressions on .NET, or you've heard about them but haven't really tried them, this tool can help you a lot. If I do say so myself.

    As an old Perl guy (in both senses of the word "old"), I've spent a fair amount of time writing regular expressions. It's easy to try out a regex in Perl, but not so easy in a compiled language like C#. I wrote the first version of this utility a couple of years ago, and in the first version, all it did was let you type in a regex, a string to run it against, and execute it.

    Over time, it grew. The next version supported some fairly cool features:

    • A menu with all the regex language options, so you don't have to remember what the syntax is for zero-width positive lookaheads.
    • Automatic creation of C# or VB code based on your regex and the options you choose.
    • Interpretation of regexes. Hover over a part of the regex, and the popup will tell you what that part of the regex means. This is very useful if you're trying to learn regex, or you don't remember what "(?<=" means.
    • Support for calling Split()

    This version adds a few more features:

    • A nicer UI. Not a very high bar, given the previous design ("Who designed this UI? Vandals?") (5 points to anybody who knows who wrote that line...). A real menubar, a somewhat-pleasant grouping of controls, etc.
    • Library functionality. Give the regex you wrote a description, and save it away into a library, so you can open it up later, or show it off to your friends. Chicks dig a well-crafted regular expression.
    • Unit tests for the interpretation features. Found 3 or 4 good bugs when writing the unit tests. These tests will get better over time.
    • Support for calling Regex.Replace(). Specify the replacement string, and you'll see exactly what gets replaced.
    • Support for calling Regex.Replace() with a MatchEvaluator. For the cases where you can't do your replacement with a simple substitution string, the Regex class lets you write a delegate. The workbench now allows you to write the function, which it saves away, compiles, loads and then uses to call Replace.

    Comments & suggestions are always welcome.







  • Eric Gunnerson's Compendium

    Getting pictures onto your computer


    If you take a lot of digital pictures (I have 7000 images on my laptop right now, and lots more archived), you spend lots of time copying files across to your computer. Most cameras come with USB cables, which aren't really that useful.

    My preferred solution is a CompactFlash PCCard adapter. You take the compact flash out, plug it into the adapter, and slide the adapter into your laptop. At that point, it looks just like a disk drive, as compactflash cards look like IDE drives. Easily copy the files across and delete the existing ones, without having to use camera power. It's also a bit faster.

    You can also get these for other storage formats.

  • Eric Gunnerson's Compendium

    Review continued - Canon G3


    (review continued)

    These two contraints - what you want to do with the aperture or shutter speed, and what the camera needs to do to give you a good exposure - sometimes come into conflict. If you take a picture of moving water, you often want a slow shutter speed (1/30th to 1 second, depending on the effect), but if it's a sunny day, you'll overexpose at that shutter speed.

    Enter the neutral-density filter. With the the filter, you get a 3-stop (3 factors of 2, or 1/8th) decrease in the amount of light that comes in. That means that instead of an exposure of F16.0 at 1/125th of a second, you can either open the lens up to F2.0, or lengthen the exposure to 1/15th of a second.

    I used this last night on some fireworks, just so the CCD sensor doesn't get overloaded.

    The cool part is that it's just a setting in the recording menu, and everything else works the way you'd expect.

  • Eric Gunnerson's Compendium

    Review - Canon Powershot lG3 Camera


    Our trip to Maui involved lots of camera issues. We're a Canon family, with a G1 for me, an A20 (the aforementioned waterlogged A20) for my wife, and a low-end Canon for my 9-year-old daughter (bought after she shot 15 rolls of APS film in Europe last year).

    My G1 has been a great camera. It's not quite as flexible as an SLR - you don't get interchangable lenses, and it doesn't zoom enough to do kid's sports, but overall I take a lot more pictures. My plan was to take the G1 to Maui with me, but 3 hours before the flight I realized that I had left it at our ski cabin, so it was time for an unscheduled upgrade. I chose the 4 megapixel G3.

    The G1 is a "prosumer" model. It has 2048x1500 resolution, decent glass, a 3x zoom, aperture and shutter priority, manual focus, a really-nice flip and tilt-LCD, and a bunch of other features I've probably forgotten. The two features that had the most effect on my shooting are the tilt-LCD (take high and low angles easily), and the multiple-exposure panorama (aka stitching) support. Both let you get shots that you just couldn't get before.

    It's amazing how much better the G3 is than the G1.

    • 4x zoom, to 140mm equivalent.
    • High-speed multiple exposure (2.5/second, up from 1.5/sec on G1)
    • lower power, faster processor
    • autofocus bracketing
    • Optional histogram display on playback
    • user-defined custom modes, accessible from the mode dial
    • neutral-density filter
    • Faster startup (4 seconds vs 8 seconds on the G1)
    • intervalometer (picture every n seconds)

    The faster processor is great, as is the high spead multiple exposure. When I take candid pictures (of kids or adults), I like to take 5 or 6 exposures in every situation, and this gets them muh faster. The better zoom is great. There are two features especially worthy of mention.

    The first is the intervalometer. I used this to take sunset pictures one night, and just set it up to take pictures while we barbecued and drank Mai-Tais. Every 55 seconds or so, the camera would turn on, take a picture, and turn off. Neat

    The second big new feature is the neutral density filter. It reduces the light by 3 stops. So, why would you want to do that?

    The two big variables in photography are aperture (how much the lens is open), and shutter speed (how long it's open). To get the right exposure, these two variables have an inverse relationship - the more the lens is open, the shorter the exposure needs to be. The aperture also controls the depth of field, so if you want everything in focus you need a small aperture (big number), or if you want the foreground and background out of focus, you need a large aperture (small number). Similarly, if you want to stop action, you need a short exposure time, and if you want to blur action, you need a long exposure time.

  • Eric Gunnerson's Compendium

    Body of Secrets - Anatomy of the ultra-secret National Security Agency


    Body of Secrets - Anatomy of the ultra-secret National Security Agency (James Bamford, Anchor Books)

    With the exception of the stillborn "Clipper Chip", the NSA has done their best to stay out of the public light. This book discusses how the NSA was formed, what it does, and how it does it. It also exposes some interesting information - that the Joint Chiefs had plans to attack Americans and blame it on Cuba, and that perhaps the same thing happened in the Gulf of Tonkin.

    After reading this book, I'm somewhat conflicted over the NSA. Sometimes, I think they're an incredible national asset, and that the intelligence they gather makes the world a safer place. Sometimes, I think they're the biggest threat to personal liberty around. And other times, I think they're an agency that has become increasingly irrelevant with the spread of the internet and strong encryption.

    Definitely recommended.

  • Eric Gunnerson's Compendium

    Maui thoughts


    Spent the last 10 days in Maui (Pictures), with no internet connection. This a a computer-free post.  

    6/25 Blue Water Rafting

    This morning, we went on a charter boat operated by Blue Water Rafting. This was a trip in a small, 7-person Zodiac-like craft. The boat left from Kihei Boat Ramp (definitely an advantage if you're staying in Kihei), and we journeyed south to the most recent lava flows (circa 1790). We spent a lot of time very close to the lava or inside some caves at the side.

    The trip included 5 stops for snorkling, including 4 sites on the west shore and the obligatory trip to Molokini. Molokini is the top of a cinder cone with a reef on the inside, and part of the cinder cone under water. It is the #1 snorkling destination on Maui. This mostly because it's fairly big and can support a lot of boats, but there are better places to journey to. It does have the advantage of being fairly sheltered, and the reef is pretty.

    1) You rent the boat, you choose where it goes.
    2) Spend time where you want.
    3) Nobody else goes close to the lava flow.
    4) Snorkel with Dolphins (if you're lucky), or off the backside of Molokini.
    5) Captains know where the fish and the turtles are.

    1) Ride is very rough (the rafting moniker is deserved)
    2) Breakfast and lunch are limited (muffins/fruit, sandwiches)
    3) Expen$ive. For the 6 person boat for 5 1/2 hours, you will pay $800. That's helicopter tour territory.

    6/25 Canon Waterproof Camera Housing

    I got my wife a waterproof housing housing for her Canon A20 camera (about $150). You put the camera in it, seal it up, and it has controls on the outside. The display might as well be off, and it's hard to look through the viewfinder, so I had my best luck pointing and shooting. It helps immensely if you can surface dive, as the fish are often 15 or 20 feet down. A nice option, especially since waterproof housings for my G3 cost around $800.

    6/26 Snorkling at the Fishbowl. Or, perhaps the aquarium. We're not sure.

    On the advice of our captain, Kim and I and my sister and brother in law decide to snorkel at the "fishbowl". It's near Ahihi marine preserve (also a great place to snorkel), but to get there you have to a) find the trailhead and b) hike for 30 minutes across the lava field. Not as bad as it sounds.

    Once we get there, we find out that this is now a destination for sea kayak tours. 3 boats when we get in there, which isn't bad, but another 20 arrive when we're snorkling, which means avoiding them and the 40 people who don't really know how to snorkel. The four of us go outside the bay, and Kim and I see a turtle, but that's about it. We come back in, dry off, and hike back another 30 minutes to the car. Not really better than Ahahi.

    6/26 Canon Waterproof Camera Housing (redux)

    Used the waterproof housing again today. My wife and I conspired together, which is never a good thing. If I had prepared the camera, it would have been fine, and if she had done it the way she wanted, it would have been fine, but unfortunately, she did what I had said, and left the carry strap on, but didn't get it tucked in sufficiently. The housing worked fine for about 10 minutes, but then I got it down about 3 feet, and it quickly filled with water.  I did all the the right things (kept it wet, soaked in in fresh water for a long time to get all the salt out), but the camera is DOA right now. I may try cleaning it more once I get home, but it's probably a goner. Sigh. Off to EBay...

    6/26 Kinston Technology 128MB Compact Flash Card

    Despite the warning on the back that says, "do not bend this card or expose it to strong physical or electrical shocks, water, solvents", the compact flash card from the camera survived immersion in salt water fine, and I was able to pull 12 pictures off of it. It's a bit like looking at the images of the Challenger before it exploded and knowing that something bad is going to happen, as you can see a bit of fog on some pictures, and then the last picture has droplets inside the lens.

    6/29 Maui Thoughts

    Maui is certainly a wonderful place. The weather in Kihei (and presumably, also in Kanapali) is perfect - not too hot, not too cool.

    Unfortunately, it appears that everybody in the Western Hemisphere feels the same way. Despite the lack of Japanese money for the past few years, prices in Maui make San Francisco prices look cheap. We're in a 900 sq. ft. one bedroom condo a block from the beach, with what is technically known in real estate circles as a water view (ie the water can be seen if you lean out over the railing). A similar unit in this building with no view is going for $200K. The place where we stayed last time (Hale Hui Kai), a condo on the water, one of the units is selling for $750K. Or, you can buy a large house 3 blocks from the beach for $800K. Oh, and if you have a condo, you also have a maintenance fee of $300 a month.

  • Eric Gunnerson's Compendium

    Off to Maui

    I'm taking a few weeks off to sit on the beach in Maui. I'm taking my laptop to store all the pictures I take, but I don't plan to be online.
  • Eric Gunnerson's Compendium

    Quiz: How do you expose a .NET object for Remoting?


    I've been working on some code to do peer-to-peer communication between .NET applications. I won't give away all the details in it right now, since my next column will be on it, but I spent a fair amount of time trying to figure out the answer to this question.

    If you look for examples in the doc, you'll find that they do something like:

        RemotingConfiguration.RegisterWellKnownServiceType( typeof(MyRemoteClass),

    This code enables somebody connecting to our program and getting a remote instance of MyRemoteClass. It's not terribly useful, however, since it's a stateless model - there's no way to get anything back other than a new instance of MyRemoteClass. What you typically would want is to hook up to an already-existing instance.

    So, I started search the RemotingConfiguration class, to see what I could find. The logical thing to do would be to have something like RegisterInstance, but there's nothing like that to be found. After about twenty minutes in Google Groups, and I find the answer.


    I note this not to show how to do this - though I think this is useful - but to highlight the problem of letting your developers name the methods in your class. While "Marshall" may make perfect sense to the class designers, it makes very little sense to me.  

  • Eric Gunnerson's Compendium

    C# Interview


    I ran into Chad Meyers from ActiveWin when I was at TechEd a week ago, and he hit me up for an interview.

    Aside: Being in a convention in Dallas is like having a fever. You're either hot and sweaty, or cold and shivering.

  • Eric Gunnerson's Compendium

    Bad Roomba!!!


    I bought a Roomba this week.

    It's a $200 robotic vacuum cleaner made by a company named iRobot (wonder if Asimov's estate gets any fee from that). Works pretty well at finding its way around the room, though the first time we ran it, it bumped into a picture leaned up against the wall. The second time it bumped against the wall, the picture fell, and landed on Roomba. Roomba got stuck, and shut off.

    After that, Roomba got scared and went and hid under out bed at the other end of the house.

    Review: Well, two sessions does not a good product make, but if you're willing to sweep the pizza boxes and cans to the side, it does a pretty good job, and it's fairly amusing to watch. You do have to hook it up to a charger (somewhat a bummer), but since you have to empty the container fairly often anyway, making that purely automatic wouldn't help much. A pretty sophisticated device.

    If I'm going to keep anthropomorphizing the thing, it really needs a better name. If you have suggestions, let me know.


  • Eric Gunnerson's Compendium



    So, who is this Eric Gunnerson? And what will he cover here?

    I'm a program manager in the Visual C# team, and I own the C# project system and our community efforts. But I must explain what "own" means in this context. "Program Manager" in many companies means "guy who's in charge of everything", but at Microsoft, Program Manager means something different. Basically, PMs are the glue that holds the company together.

    I also write an MSDN C# column named "Working with C#" (no, I didn't name it) , and I'm the author of "A Programmer's Introduction to C#" from Apress.

Page 46 of 46 (1,149 items) «4243444546