Advanced Basics

Visual Studio .NET 2003 Usage Tips

Ken Spencer

Q When I'm working on a solution with many projects and assemblies, the Visual Studio® .NET IDE seems slower; the same is true when there are fewer assemblies and more code in each assembly. Ctrl+Tab switching between code view and design view takes a lot more time and sometimes the IDE locks up because background compilation hangs. Do you have any suggestions that would help me to improve performance?

Q When I'm working on a solution with many projects and assemblies, the Visual Studio® .NET IDE seems slower; the same is true when there are fewer assemblies and more code in each assembly. Ctrl+Tab switching between code view and design view takes a lot more time and sometimes the IDE locks up because background compilation hangs. Do you have any suggestions that would help me to improve performance?

A The most likely cause of your slowdown is the background compile process used by Visual Basic® .NET. Background compiling has been around a long time and provides some of the immediate feedback developers find so convenient. For instance, if the compilation finds an error, you can fix it in the editor and the background compiler checks it for you when you move on to another line. Overall, this makes for a productive development process, unless the compiler takes up so many cycles that it slows you down. Of course, if you have a solution that contains many thousands of lines of code, this process may bog down the system.

A The most likely cause of your slowdown is the background compile process used by Visual Basic® .NET. Background compiling has been around a long time and provides some of the immediate feedback developers find so convenient. For instance, if the compilation finds an error, you can fix it in the editor and the background compiler checks it for you when you move on to another line. Overall, this makes for a productive development process, unless the compiler takes up so many cycles that it slows you down. Of course, if you have a solution that contains many thousands of lines of code, this process may bog down the system.

I don't run into this problem very frequently because I always break down projects into smaller chunks. Then I create a solution that is relevant to the current part of the application I'm working on but also has references to the DLLs in other parts.

That said, Visual Studio .NET 2003 fixes the background compile problem for large projects. Along with this and other improvements, the Visual Studio .NET 2003 IDE seems snappier in general than Visual Studio .NET 2002. These changes make the IDE much better for large projects. My testing was done with the final beta, so you may even see better performance when the final release ships.

There are other features that help performance in large solutions. Often, you may have a solution that groups lots of projects together for convenience, thus allowing you to access each project directly as needed. However, it adds to the build time when you press F5 to run and test your application, and every project in the assembly is built. Now you can configure Visual Studio .NET 2003 to build only your startup projects and any dependencies for those projects. For instance, if you have 20 projects in a solution and only 5 of them are required to be rebuilt each time you run the application, that takes 75 percent of the projects out of the build process during a test run. This should result in much faster test runs, depending, of course, on the total number of projects that you are running and their size.

This feature is controlled by a new setting in the Tools | Options | Environment folder on the Projects and Solutions dialog. The "Only build startup projects and dependencies on Run" option defaults to False. If you select either the Visual C++® or Visual C#® developer, the option is set to True. Figure 1 shows this dialog with the setting changed to True.

Figure 1 New Options in Visual Studio .NET 2003

Figure 1** New Options in Visual Studio .NET 2003 **

There is another change that may affect large applications during the build process. In the past, you could only set one Visual Basic project as the startup project. This has been true for all versions of Visual Basic, including Visual Studio .NET. Visual Studio .NET 2003, however, allows you to select multiple startup projects, as shown in Figure 2.

Figure 2 Selecting Startup Projects

Figure 2** Selecting Startup Projects **

An example of multiple startup projects involves .NET Framework Remoting. If you build a .NET Framework Remoting application and create your own host app, each time you test the application you must make sure the host is running before the client tries to access it. Now you can flag both projects as startup projects in a single solution and each time you press F5, both projects start. This makes solutions really good containers—not only for development but also for testing when you need to open projects and run multiple applications. Stopping any of the startup applications seems to stop the run session and all applications.

Now, consider both the ability to only build startup projects and their dependencies and the ability to have multiple startup projects. Consider an example where your solution has 10 projects. Let's say you have one project that you want to start all the time and there are three other projects it depends on. That only requires the building of four projects. But you can configure another startup project and allow it to have all of the other projects as dependencies. Then you can switch between the two startup projects and change what gets compiled. This makes moving back and forth between build processes as simple as changing the startup projects.

Q I have two questions related to building Windows®-based applications that would both save coding time and possibly improve the performance of my application. First, how can I determine if a DataReader has rows without having to read the data? Second, is there an easier way using Windows Forms to allow a user to select a folder that requires less code?

Q I have two questions related to building Windows®-based applications that would both save coding time and possibly improve the performance of my application. First, how can I determine if a DataReader has rows without having to read the data? Second, is there an easier way using Windows Forms to allow a user to select a folder that requires less code?

A One of the changes in Visual Studio .NET 2003 is the DataReader. The new HasRows property enables you to check for rows without reading any data from the DataReader, resulting in faster tasks when connected to the DataReader.

A One of the changes in Visual Studio .NET 2003 is the DataReader. The new HasRows property enables you to check for rows without reading any data from the DataReader, resulting in faster tasks when connected to the DataReader.

Web Services have some interesting changes as well. First, there are changes to the way you access Web Services. The Add Web Reference dialog now lets you select Web Services from your local system, a Universal Description, Discovery, and Integration (UDDI) directory, or UDDI servers on your network. The Add Web Reference dialog makes working with Web Services simpler and improves not only the time required to access them, but reduces the tasks required to accomplish this.

Windows Server 2003 includes a new UDDI service, which provides a repository for storing information about Web Services. This will make it easy to hook up applications to Web Services that are referenced with the UDDI service, so your developers can easily find and consume Web Services on your network.

The Add Web Reference dialog has also changed, as shown in Figure 3. This is helpful because not only can you connect to the Web Service, but you can also change the name of the folder that contains the Web reference before it is configured.

Figure 3 Add Web Reference

Figure 3** Add Web Reference **

One the client side, I found a new Windows Forms component that will also speed up the development process for Windows-based applications. The FolderBrowserDialog control provides a neat dialog from which you can easily select a folder. This allows you to drop this control on a form and wire it up with a few lines of code. The component also allows a user to create a new folder.

After you drop the component on a form, you can set several options and then display the dialog. The following code sets the starting (rootfolder) of the dialog to either the Desktop folder or MyComputer folder:

   If rdoDesktop.Checked Then
   FolderBrowserDialog1.RootFolder = _
       Environment.SpecialFolder.Desktop
   Else
   FolderBrowserDialog1.RootFolder = _
       Environment.SpecialFolder.MyComputer
   End If

The next few lines of code either turn the dialog's New Folder button on or off:

If rdoNewTrue.Checked Then
   FolderBrowserDialog1.ShowNewFolderButton = True
Else
   FolderBrowserDialog1.ShowNewFolderButton = False
End If

You can also control the description of the dialog by setting the Description property:

FolderBrowserDialog1.Description = "Select folder for files"

To display the dialog, you call the ShowDialog method. This method returns a dialog result that you can check to make sure the user selected a file:

If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then

Finally, you can retrieve the path selected by the user:

   StatusBar1.Text = FolderBrowserDialog1.SelectedPath
End If

The Environment.SpecialFolder enumeration returns an integer that represents a special folder on your system. You can use it to set the start folder for browsing, as shown earlier. This enumeration is also handy to use any time you need to allow the user to select one of these folders.

Also noteworthy is the new Enterprise Instrumentation Framework (EIF), which provides a framework to instrument your application. The vast majority of applications do not have good instrumentation because it's not part of the specification, and developers do not always take the time to implement it. The EIF makes this much easier to do, so hopefully more developers will instrument their applications.

To top off what I think are the cool features of the .NET Framework 1.1 release, you now get Oracle data providers. You can use these data providers right out of the box (or download) to connect to and work with an Oracle database without having to download, install, and configure them separately.

Now you've seen just a very few of the reasons to upgrade to Visual Studio .NET 2003. Since Visual Studio was first introduced, each new version has improved upon the previous one—that's why you upgrade. But it gets better: Visual Studio .NET 2003 and the .NET Framework 1.1 can be installed on the same system that continues to run Visual Studio .NET 2002. You don't have to throw out Visual Studio .NET 2002 just because you want to start using Visual Studio .NET 2003 for some projects.

Send your questions and comments for Ken to basics@microsoft.com.

Ken Spencerworks for 32X Tech (https://www.32X.com), where he provides training, software development, and consulting services on Microsoft technologies.