VS2005 Windows Form Application Slow? My speed tips.

For the past few months I’ve been working almost exclusively in Visual Studio 2005 doing Windows Forms, in my past I haven’t done any serious windows form work since Visual Studio 6 with the majority in Visual Studio 3.0 (yikes! 16bit!) . Most of my time since then was spent doing web applications.

One thing I have learned is that by using traditional methods your visual studio application will be a slow beast.

I’ve found a few things that really speed up your application, and I’ll try to write an in depth post on each one.
1. Use BeginUpdate/EndUpdate and ResumeLayout/SuspendLayout whenever updating controls.

    Example: Coming Soon.

2. DoubleBuffer your form.

    Example: Coming Soon.

3. DoubleBuffer some controls, if they don’t allow it, create your own class.

    Example: Coming Soon.

4. Use a background worker process.

    Example: Coming Soon.

5. Do some work in the Application Idle event

    Example: Coming Soon.

6. When working with slow controls like the TableLayOutPanel, try using anchor instead of dock

    Example: Coming Soon.

7. When working with datacolumn object be sure to dispose of it when finished.

    Example: Coming Soon.

8. When working with graphics, dispose of Pen objects when no longer needed.

    Example: Coming Soon.

9. If you use databinding on your controls make sure you do it first.

    Example: Coming Soon.

10. Use performlayout()

    Example: Coming Soon.

11. Use Microsoft’s performance tool to identify problem functions.

    Example: Coming Soon.

By just employing some of these tactics your users should at very least get a better user experience and perhaps you will get some boasts in performance.

Make your classes serializable.

I’ve done a little of this in the past, and I’m about to do it today. Each time I have to look it up, so in hopes of finding it a little quicker or maybe remembering how this time, I’ll post it here.

From: MSDN – Custom Serialization


_
Public Class MyObject
Implements ISerializable
Public n1 As Integer
Public n2 As Integer
Public str As String

Public Sub New()
End Sub

Protected Sub New(ByVal info As SerializationInfo, _
ByVal context As StreamingContext)
n1 = info.GetInt32("i")
n2 = info.GetInt32("j")
str = info.GetString("k")
End Sub 'New

_
Public Overridable Sub GetObjectData(ByVal info As _
SerializationInfo, ByVal context As StreamingContext)
info.AddValue("i", n1)
info.AddValue("j", n2)
info.AddValue("k", str)
End Sub
End Class

Empty ClickOnce Error Message

Well, this error is pretty much the entire reason I decided to start my own blog. During the work day, I often look to the internet for the solution to errors or coding help. I feel I’ve become quite handy with google.com and rarely am I stuck with a problem for more than a few minutes.

Then I met this error. I even actually opened up an incident with Microsoft, something I once thought I’d never do. I’m not a Microsoft hater, nor do I doubt the answer was somewhere at Microsoft, perhaps by a lot of employees. But, I know how large corporations work, and it’s just frustrating working your way up the call ladder to get to someone who can actually help. I’d probably find a solution quicker by just formatting my machine and started from scratch.

Enough with the introduction, here’s the error.

At work I’ve developed an application that was to be deployed by clickonce. I published several versions and everything appeared to be working perfectly. We began to test the application on a wider range of machines as it came closer to application’s release date. It turns out that the ClickOnce applications that I was publishing, would not work on any machine that did not have all the prerequisites. If a machine was lacking any prerequisites, you could click on the “Install” button on the publish.htm but the user was instantly prompted by two empty dialog boxes.

error

 

As you can see, it’s very descriptive.

Anyhow, after some digging on the client machine, I did find an error in the Windows temp directory.

Error: An error occurred attempting to extract setup configuration file.
The following error occurred initializing the bootstrapper: “An error occurred attempting to extract setupconfiguration file.”

Google doesn’t bring up much on this error.

I had other developers try publishing the application after downloading it from source control. They had no problem publishing a working setup.exe. This problem was limited to my machine. So, I began creating new completely blank projects and immediately tried to publish them via clickonce. I got the same result each time. This problem was plaguing my entire machine, not just ClickOnce.

So, I started looking at the setup.exe my machine was publishing. Turns out my setup.exe was always 320kb. On the other development machines, they were 422kb. My setup.exe were a valid win32 image but, obviously they were missing something. I found out you could drag setup.exe’s into Visual Studio and examine them, so I did this:

badsetupexeresourceview

Bad Setup.Exe

 

 

And the good one:

goodsetupexeresourceview

 

Pretty major difference, right?

So, I searched my machine and found in previous projects my setup.exe were 422kb, so I had a time frame of where something went wrong. In one previous project I did a lot of work with certificates, so I spent some time trying to see if certificates were working on my machine, no luck.

Finally, I decided to remove a few programs each morning at work. (At the same time I was getting emails from my assigned Microsoft Tech telling me he thought it could be Firefox on the client machines). On the second day, I removed two programs: Microsoft’s WSE (Web Services Enhancements) 3.0 and .NET Memory Profiler Trial Version 3.0 by Scitech Software.

I loved the .NET Memory Profiler but my trial ran up and I even sorta forgot it existed, so I removed that. I still needed WSE but I was so convienced something with certificates had messed this up, I had to remove it.

Lo and behold after the removal of these programs, everything works again.

I reinstalled WSE and tried ClickOnce again, and everything was still fine.

I kept WSE and installed .NET Memory Profiler and my setup.exe was corrupt again. So, I’m somewhat certain that it was just the Memory Profiler but, I can’t say with 100%.

What I can say, is if you are having this problem, please remove WSE and any IDE add-on’s you have. Perhaps do it one at a time.

I let Microsoft know they could close my incident that although firefox on the client machines was a damn good suggestion (dripping sarcasm) but it was actually WSE or .NET Memory Profiler. I received a congratulations and was told that “WSE and ClickOnce is a known issue” Of course that pissed me off, I wish I would have been told that during the first phone call when I asked if anything could interfere with that.

Hope this saved someone out there some time that I lost.
UPDATE (3/14/08): Microsoft did refund my incident here. So, no harm no foul. Perhaps I’ll try their support again one day.

UPDATE (11/13/08): I’ve been using clickonce nearly daily since this incident and not one problem since. I have recieved some feedback from other people with this same issue, and it always seems to be solved by uninstalling some plugin software to visual studio. So, I believe the ultimate answer to this issue is to remove your plugins one by one.