Getting Dumpprep.exe to leave me alone

Everytime a program on my computer hangs or crashes, dumpprep.exe spins for a long time getting a dump report ready for microsoft.  Only problem is, I never send the report, because I need to get back to work.  So all that time is wasted.

Thankfully, you can turn off this time wasting “feature”:

1. System Properties (Either via System in Control Panel, or Getting Properties on My Computer)
2. Advanced Tab, and choose “Error Reporting”. Set to “Disable Error Reporting”
3. You could also Select “Startup and Recovery” – Settings button, and change “Write Debugging information” from complete to none.

Credit goes to Peter Collinson

Using My.Settings on a referenced project

I recently ran into some seemingly strange behavior as I was testing a couple windows services I had written.

In my case, I had a test harness program that was referencing the service (an exe) but this could also apply to references to dlls if you are using the projects application settings (My.Settings.Whatever in VB.Net).

After figuring it out, it all makes sense.

When you create an application setting by providing a value in the project’s “Settings” tab, the value is written out into a special <applicationSettings> block in your config file.

But, in order to make those values accessible via a strongly typed/intellisense method, a class is created to wrap those values.  The class is in the Settings.vb file that is generated when you first add an application setting to your project.

But there is one more interesting thing to note:  If the settings class doesn’t find the item it expects in the config file, it will return the last supplied value by default. 

So what this means is that if create an application setting for XYZ for the value “123” and then change the app.config file directly to change the “123” to “abc”, then “abc” will be returned when you run the program.  However, if you were to then alter the config file to remove or rename the XYZ item, then your application would return “123” again when it ran.

Also, if you directly modify the config file, and then try to edit the projects applications settings, it will alert you to the fact that some values have changed, and ask if you want to use the updated values from the config file.  If you say yes, it will overwrite the Settings.vb file to use the new values that you had supplied in the config file.

So, I was referencing a project that used these settings, but when I would update the config file, those updated settings were not seen.  All I had to do was go into the project settings tab, allow it to refresh the Settings.vb file, and rebuild the project.


TFS Source Control "No Commands Available"

I just opened VS to do something in TFS Source Control Explorer only to find that all my controls were disabled and right clicking on anything only showed “No Commands Available.”

Turns out that this was because I had to change my default source control plugin to VSS for a project I was working on.  If you go to Tools->Options->Source Control and select TFS as the default SCC plugin, it will fix the problem.

Right aligning text when printing from a .net program

In a program I am writing, I need to print directly to a couple of label printers.

My God these things are a pain in the ass to work with, but I will leave that rant to another post.

One thing I ran into was how to right align text when using the DrawString method of the System.Drawing.Graphics class off of the PrintPageEventArgs.

The solutions I was coming across seemed about as bad as I was expecting.

They involved measuring the width of the line of string using some System.Drawing.Graphics.MeasureString to figure out the length, and then dynamically position the text to make it appear right aligned.  So what that means is that for short text, X would be greater and for long text X would be less.

Fortunately, I came across the most simple solution:

Dim s As New StringFormat()
s.Alignment = StringAlignment.Far

e.Graphics.DrawString("por que?", New Font("Tahoma", 8), Brushes.Black, 50, 50, s)

Very simple.  But you have to wonder, why did MS pick “Far” as the alignment name instead of “Right”, as you would expect.  Maybe “Far” is more of a graphics term for alignment?  Who knows.