[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Browsing folders and files with System.diagnostics class slooooowwww after convert C#2003to #2005

Question pertains to C#
Hello,
I just converted a C# 2003 solution over to C# 2005. Everything seems to work fine right away except:

I am using System.Diagnostics in several windows forms to open and manipulate files. E.g.
string ObsSpDAtaXMLFolder = @"C:\Management\ExportFiles\Text Files";
Process.Start(ObsSpDAtaXMLFolder);

note. It does not matter what computer I am running on...

This code works GREAT when built with C#2003 but the browsing is dreadfully sluggish in C#2005. Is there a better way to do this in C# 2005??

Thanks
0
Saxitalis
Asked:
Saxitalis
  • 7
  • 3
  • 2
1 Solution
 
JimBrandleyCommented:
Could you post ther rest of the code used to define the process?
0
 
SaxitalisAuthor Commented:
This is literaly all of the code to define the process:
//all other user references
using System.Diagnostics

private void btnOpenXML_Click(object sender, System.EventArgs e)
{
      try
      {
         string DataXMLFolder = @"C:\Management\ExportFiles\Text Files";
         Process.Start(ObsSpDAtaXMLFolder);
      }//end try
      catch(Exception ex2)
      {
      }//end catch
                  
1. I am saving the location of the folder to open in a string variable
2. I pass this string variable to the Process.Start(string variable) method of the System.Diagnostics class.

This works fin in VS 2003 but takes a couple of 60 to 90 secs to browse in VS 2005 build ???
                  
0
 
JimBrandleyCommented:
Is Text Files an executable?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
SaxitalisAuthor Commented:
Text Files is just a folder
@"C:\Management\ExportFiles\Text Files"; is a folder location
0
 
JimBrandleyCommented:
Maybe I'm missing something here. System.Diagnostics.Process allows you to launch an external process. What process occurs if you just pass a location?
0
 
SaxitalisAuthor Commented:
Hmm I guess I don't completely understand why it works but this is a Windows form. When I click the button represented by the method above, the form browses to the location passed in.

Should I be doing this another way??

Thanks for your patience here :)
0
 
JimBrandleyCommented:
This will open the folder browser window, and allow you to use it in the form, and it is fast.
private void SelectAndUseFolder()
{
   // First, pop up a directory selector so the user can change or accept the current one.
   FolderBrowserDialog dlg = new FolderBrowserDialog();
   dlg.Description = "Select project directory";
   dlg.SelectedPath = myDefaultPath;
   dlg.ShowNewFolderButton = false;
   DialogResult result = dlg.ShowDialog();
   if (result == DialogResult.OK)
   {
      string myNewPath = dlg.SelectedPath;
      // If everything else is set, it will be loaded.
      // Do something here
   }
}
Does that help?
0
 
JimBrandleyCommented:
BTW - Problem solving is enjoyable for me. To paraphrase Bertrand Russell - First you have to pose the question in such a way that it can be answered. So, that's just a part of the solution process.

Jim
0
 
Bob LearnedCommented:
BTW, try that without the try/catch, and see if it is any faster.

Bob
0
 
JimBrandleyCommented:
Bob - Why would the try slow it down? Is that because it's an external process, and It needs to wait for a result?

Jim
0
 
Bob LearnedCommented:
1) I don't use try/catch blocks if I am not going to do anything.  This can be handled higher up.

2) Try/catch blocks add a layer of complexity to your code that may not be necessary.

3) They should be used carefully, and for specific purposes.

4) Case in point:

http://www.nullify.net/ViewArticle.aspx?article=220

Comparison of speed of try..catch checking of integers
1000 iterations of try...catch Convert.ToInt32()
2515.625 ms total
100000 iterations of Double.TryParse() (to be fair!)
46.875 ms total

5) If you are going for efficiency, avoid use try/catch.

Bob
0
 
JimBrandleyCommented:
I knew about the first three points - did not know th rest. Thanks!

Jim
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now