locked
[Visual C#] how to resolve freezing application? RRS feed

  • Question

  • I've been solving how to resolve freezing application especially when you are using loops and socket authentication. one good example is this...

    string driveX = "C:\";

    foreach (string d in Directory.GetDirectories(driveX))
    {

    string[ filePaths = Directory.GetFiles(d, "*.*");
    foreach (string fileX in filePaths)
    {

    listBox1.Items.Add(modifiedMD5(fileX));

    }

    }

    anybody can resolve the freezing problem?

    coz my real problem is connecting to a server... check it out my test project guide, http://camilord.kagayan.com/2009/04/13/visual-c-connecting-to-mysql-remotely/
    Monday, April 13, 2009 11:43 AM

Answers

  • Hi Camilo,
     Threads is the best option here. Have a look at msdn help for threads. Move the logic to a thread and have a spinning progress bar or something like that.

    Regards
    PKR
    • Proposed as answer by Guo Surfer Wednesday, April 15, 2009 5:28 PM
    • Marked as answer by Guo Surfer Monday, April 20, 2009 3:05 AM
    Monday, April 13, 2009 11:53 AM
  • I agree with Vic,

    The main cause of the delay is the multiple foreach loops. you can move that logic to a seperate thread and store all the filenames in an arraylist.

    Once that is done you can set the datasource of the list to the ArrayList.
    Ganesh Ranganathan
    [Please mark the post as answer if you find it helpful]
    • Proposed as answer by Guo Surfer Wednesday, April 15, 2009 5:28 PM
    • Marked as answer by Guo Surfer Monday, April 20, 2009 3:05 AM
    Monday, April 13, 2009 12:58 PM

All replies

  • Hi Camilo,
     Threads is the best option here. Have a look at msdn help for threads. Move the logic to a thread and have a spinning progress bar or something like that.

    Regards
    PKR
    • Proposed as answer by Guo Surfer Wednesday, April 15, 2009 5:28 PM
    • Marked as answer by Guo Surfer Monday, April 20, 2009 3:05 AM
    Monday, April 13, 2009 11:53 AM
  • I agree with Vic,

    The main cause of the delay is the multiple foreach loops. you can move that logic to a seperate thread and store all the filenames in an arraylist.

    Once that is done you can set the datasource of the list to the ArrayList.
    Ganesh Ranganathan
    [Please mark the post as answer if you find it helpful]
    • Proposed as answer by Guo Surfer Wednesday, April 15, 2009 5:28 PM
    • Marked as answer by Guo Surfer Monday, April 20, 2009 3:05 AM
    Monday, April 13, 2009 12:58 PM
  • ok.. i will test your recommendation.. thanks.. :)
    Monday, April 13, 2009 10:25 PM