Posted by Ben on July 26, 2010
If you’ve got to serialize some data, especially in a binary format, it’s common to output the length of the data. This is useful for versioning, random access, knowing when you’re done reading the records, among other reasons. Therefore, you need to know the size of the data you’re going to serialize. There are a [...]
Posted by Ben on March 8, 2010
Well, it’s finally out! Amazon no longer lists the book as available for pre-sale, and it should be shipping to purchasers today or tomorrow. If you’re a B&N shopper, you can also order it there, or grab it in stores within a few days. From the product description: Real Solutions for C# 4.0 Programmers Need [...]
Posted by Ben on November 21, 2009
If you want to place a window at a specific place in WPF, it will work pretty much as you expect—unless your DPI is 120 (the default is 96). Here’s a sample that shows how to put it where you want. In this case, I want to put a window just under another control, aligned [...]
Posted by Ben on November 16, 2009
When WPF first shipped, there was a noticeable lack of certain controls we’ve become used to in Win32 and WinForms: Calendar, DateTimePicker, and NumericUpDown. WPF 4 adds Calendar and DatePicker, but not anything for numeric entry. For my solution I wanted something that behaved very similarly to the WinForms NumericUpdown control. Some of the specifications: [...]
Posted by Ben on February 4, 2009
I made a important changes to the CPU usage code and have updated the article to reflect it. Instead of a critical section, the code uses just the interlocked increment/decrement functions. I also updated the sample demo to use multiple threads to read the CPU usage to demonstrate the thread safety clearly.
Posted by Ben on January 3, 2009
My first book, C# 4.0 How-To is now shipping! If you like tips you can use, check it out! Updated 2/4/2009: I changed the implementation of these classes from the original: Instead of a critical section, InterlockedIncrement/Decrement is used. The sample driver program now demos using multiple threads using the CpuUsage class to show thread [...]
Posted by Ben on December 12, 2008
This is a simple, but useful tip. Users of WPF are spoiled. They have all sorts of layout options. Those of us still working in WinForms have FlowLayoutPanel and TableLayoutPanel. That’s it. WPF has those and more. For my current project, I needed a panel to layout controls vertically. The TableLayoutPanel can be awkward to [...]
Posted by Ben on September 13, 2008
I’ve been working on a project using Visual Studio Tools for Office 2008 (VSTO) and at one point I needed to get the colors for categories in Outlook 2007. There are actually 3 colors, and they are returned as uint’s–why the .Net wrappers don’t convert to colors for you, I don’t know (to avoid linking [...]
Posted by Ben on May 13, 2008
Tracking changes in database tables is an incredibly useful feature–especially for operational data that can change often. Having recently had to implement this feature, I thought I’d share some of the techniques I learned. Sample Database First, let’s conceptualize a very simple database consisting of user information (name, date of birth), and e-mails. A user [...]
Posted by Ben on April 17, 2008
This kind of thing has happened to be a few times now, so I thought I’d share the fun. In one of our pieces of software we have a process that looks like this: void MyThread() { while (true) { DoFunctionA(); DoFunctionB(); SleepFor10Seconds(); } } While FunctionA and FunctionB are conceptually similar, they interact with [...]