Form responding slow

Hi,

I got 2 forms. From1 has buttons and some checkboxes to start a test after a button is pressed.

If a button is pressed, it opens Form2. When i'm done with Form2 i close it.

Then i get back to Form1 and then it starts responding slow.

This only happens when i start a test that has filestreams and filereaders and some more stuff with files involved.

How can i see whats making it slow I disposed everything in Form2 when it gets closed.

Even when i close the Form1 its still running, I have to press the 'stop' button in order to continue.

Any suggestions anyone

Thanks in advance!


Answer this question

Form responding slow

  • daniel mark

    Time to break-out the debugger. Set a breakpoint on the DoEvents() call. From there, figure out why the loop isn't exiting...


  • qwv

    You've still got code running, stuck in a loop. Using DoEvents


  • Kevin Dente


    Hi nobugz,

    I got it fixed. I did a "rollback" on my code and tried it again with that peace of code, and it works.

    Also, i did it in the wrong while loop.

    So... problem solved.

    Thank you for your time and patience!

  • Kirkvq

    Try to comment parts of your code and run to acote the responsable code fragment.

    In the task manager view large amount of cpu usage



  • donkaiser

    No, your while loop keeps running, as you found out. To break out of the while loop, set a boolean form class member to true if the FormClosing event, one you test in the loop. For example:

    public partial class Form1 : Form {
    public Form1() {
    InitializeComponent();
    }
    private bool mBreakLoop;
    private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
    mBreakLoop = true;
    }
    private void DoWork() {
    mBreakLoop = false;
    while(!mBreakLoop) {
    // Do the work
    // ...
    Application.DoEvents();
    }
    }
    }




  • Prasenna


    Hi guys,

    Thank you for your reply.

    I got DoEvents in a while loop which is in Form2. But if i close Form2 isn't DoEvents stopped too, or do i have to stop it with code

    On Form1 i don't have anywhere 'DoEvents'.

  • NeilL


    Hi nobugz,

    I did exactly what you told me to do. The problem still remains.

    I have nothing on 100% cpu usage when i run my app.

  • Form responding slow