in

ASP.NET Weblogs

Philip Rieck

Phil in .net

January 2004 - Posts

  • WaitHandles for the confused

    I put up a somewhat old writeup on the ManualResetEvent and AutoResetEvent on my full blog, thought since it was .net, I'd post here as well.  Here's an excerpt:

    Confused about WaitHandles? Sure you are. For one, they have the word "Event" on them.. Are they events? Do they call delegates?. For another, what's this "Reset" action, and why would I want to do it manually? And lastly, what does the documentation mean when it says "Signaled" and "Nonsignaled"? In project [codename] you see a good number of calls to WaitHandle-derived objects , both AutoReset and ManualReset. As the interaction can be somewhat complex, it can be difficult to decipher what is going on. Hopefully this simplified example will help clear things up.

    You can find it here if you're interested.  It really was written for interns, but if you've never used them, you might find it useful.

  • Sharing my oft-used Ink controls, part 1.

    I do a good amount of TabletPC development, pretty much mostly for myself.  I have lots of fun and useful apps that do things I need, and some apps I use to demo the Tablet to others..

    And, like any developer, I hate to redo work.  So I created a library of controls that I use that I can drop-in.  I showed these to a friend today and she said “Share with the world!”.  So here you are.  This is the first one that I would even consider letting anyone else look at, and it's not a control I'd consider anywhere near polished.  But perhaps you other TabletPC developers out there can use and adapt this to reduce some of the “gruntwork”.

    So, here's the TabletTextbox - it's an Ink input control that I use on a lot of forms to quickly input text / numbers whatever.  It allows quick retrieval of the recognized text with the .Text property, and can optionally show a field label and / or the recognized text inside the control (each can be put in one of the four corners, or omitted).

    Here's a runtime screenshot of four instances of it with different properties:

    And here's where to get the source for the TabletTextBox

    Feel free to do what you want with it. If you find nasty bugs, comment here and I may fix them. Even better, if you fix the nasty bugs or add features, comment here if you like so that I can use those fixes myself!

    [cross-posted from Philip Rocks, Philip Rieck's new-ish real blog - here.]


  • Strongly typed dataset tip

    While doing code reviews (for .net code, of course!),  I see one minor annoyance with strongly typed datasets again and again - not using the TableName property.  I don't know why this comes up so often, so I thought I'd add a quick tip about it.

    If you have a strongly typed dataset (some call them XSD datasets), great. You don't need to remember column names or worry about casting values.  So why do I see things like this:

    dAdapter.TableMappings.Add("Table1", "MyTable");
    //or
    cntrl.DataMember("MyTable");

    Instead of using the table's name as a string, use the .TableName property as such:

    dAdapter.TableMappings.Add("Table1", typedSet.MyTable.TableName);
    //or
    cntrl.DataMember(typedSet.MyTable.TableName);

     

    Now you can rename your table and let the compiler find all of the code you need to change, instead of trying to do a “Find” and hoping you didn't miss any.  I'm all about making the compiler find as many problems as I can.

    [cross-posted from Philip Rocks, Philip Rieck's new-ish real blog - http://philiprieck.com/blog/archive/2004/01/21/152.aspx]


  • Don't loose this regex

    I really wish I knew where I found this... but after only an hour of digging in my old code, I found the regex to deal with CSV files (that is, handle both quoted and non-quoted values, commas in quoted values, etc).

    I know I didn't write the regex pattern. I also know I don't want to lose this and have to try.

    // ,(?=([^"]*"[^"]*")*(?![^"]*"))

    Regex rex = new Regex(",(?=([^\"]*\"[^\"]*\")*(?![^\"]*\"))");
    string[] values = rex.Split( csvLine );
    foreach( string v in values)
    {
       ...
    }

    If you have an attribution for me, please let me know. I'd like to give credit to the regex author.

    [update] - yes, it was from here : http://radio.weblogs.com/0117167/2003/02/18.html#a132  (that's from Early and Adopter)   (thanks, Darren Neimke!) 

    [cross-posted from Philip Rocks, Philip Rieck's new-ish real blog - http://philiprieck.com/blog/]

More Posts