regain control

I have a form with several components. After I selected options from couple of listboxes i then click on a button to perform an infinite loop. my problem is that while the application still running, i want to make a new choice of my option, and then hit the run button again. but since im application is in a loop it doesn't response spontaneously to my action on the form.

What is a good way to solve this kind of problem


Answer this question

regain control

  • Asim Ahmed

    I'm not sure what he's doing with an infinite loop but try putting Application.DoEvents() in your loop.

    However, as the other guys said a backgroundworker object has all the thread stuff built in so you don't have to worry much about it, or simply create a thread of your own.

  • Karl Diethrick

    I think so also.. you have to realize that VB was originally made to make programming possible for those who don't really know how... so in vb5 it may work but it is not that C# is making it difficult it is just that you need to do it the right way which in the end will be much cleaner and better implemented.

    Also you may want to consider how often you need to draw whatever it is you are drawing.  And only do it so many times per second etc.  I wouldn't just be drawing it as fast as your computer can handle.  Make it do it X amount of times a second by using a Sleep on that thread or a timer or something. (I'm not sure what you are doing, I'd have to think about the best way)

  • Vlince

    you have to consider BackgroudnWorker component in order to execute task in child thread and keep main thread responsive.

    When you execute new query you cancel old one and execute new

    hope this helps



  • Aaron77

    If you need to pass in parameters, you can wrap a thread in a class and add properties to the class for the parameters needed. Or you can use a ParameterizedThreadStart delegate to pass parameters to a thread.

  • still_the_same

    It seems pretty complicated to create a new thread then i need to worry about passing parameter and so. in vb5, there's no such problem.

  • Landarzar

    Application.DoEvents() seems to be the quickfix. but I need to draw some graphical components inside the loop and DoEvent() just disrupt the flow of the drawing. I guess thread is the best fix but it will take more work. What do you think

  • regain control