Updated CPU usage article

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.
Popularity: 6% [?]No tag [...]

Popularity: 6% [?]

Determine CPU usage of current process (C++ and C#)

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 safety.

Download the C++ and C# projects that accompany this article.
Just to make it clear, there is no API called GetProcessCpuPercentage(). To [...]

Popularity: 15% [?]

An easy stack layout panel for WinForms

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 work [...]

Popularity: 11% [?]

Converting OLE_COLOR to System.Drawing.Color

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 [...]

Popularity: 10% [?]

Tracking database changes using triggers

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 can have [...]

Popularity: 6% [?]

In this universe we obey the law of commutativity

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();
[...]

Popularity: 4% [?]

GetTextExtent vs. DrawText (with DT_CALCRECT)

Working on an MFC app that has just been converted to Unicode (finally!), I noticed that one button (which is created dynamically) is too small to fit the text in Korean (and Russian and a few other languages).
The code was calling something like:

CSize sz = m_btAdjustColors.GetDC()->GetTextExtent(sCaption);

It seems correct, but these script languages are throwing it [...]

Popularity: 5% [?]

How to file good bug reports (from Frank Kelly)

This is an issue I run into constantly at my job.
Frank Kelly wrote up a good summary of some items. They’re simple, easy to understand, easy to follow, even for non-programmers.
In fact, I’m sending this link out to everyone in my group here at work.
Technorati Tags: testing,programming,bug reporting
Popularity: 5% [?]
Tags: bugs, Links/News, programming, [...]

Popularity: 5% [?]

Never make assumptions about performance

The importance of measuring performance changes is a topic that has been covered by others smarter and more experienced than me, but I have a recent simple tale.
I’ve simplified the code quite a bit in order to demonstrate the issue. Suppose I have a wrapper around an image (it has many more attributes):

[...]

Popularity: 5% [?]

Tip: Easily Automating use of WaitCursor

This is really simple and probably common, but it’s a useful tip anyway.
Say you need to set a form’s cursor to the wait cursor while you accomplish something.
You would do something like this:
this.Cursor = Cursors.WaitCursor;
 
//do something
 
this.Cursor = Cursors.Default;
Of course, what if “do something” throws an exception? Then your cursor won’t be set back to the [...]

Popularity: 7% [?]