Program Freezes till it finishes execution

Posted on 2003-11-23
Last Modified: 2010-05-03
I'm having this problem with whatever code I write in VB .NET.  When I click the execute button in the application, and supposing the execution process takes 20 seconds, then the program completely freezez during these 20 seconds and it then gives me the output.

Which also implies that, if I want to change a textbox's contents during these 20 seconds, it won't change.  Becuase the program is in this strange state of denial!!
Question by:wireframe9

Expert Comment

ID: 9806180
in vb6 use the DoEvents method
i don't know if it works for .NET or not

There Are 10 Kind OF People
Those Who Understands Binary AND Those Who Don't
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9806623
You most likely have a loop in your application which is causing the unresponsiveness to occur.  While your program is executing the loop, it cannot process other messages intended for it such as button clicks, minimize, etc.

By adding


to the inside of your loop, you will allow your program to process any messages in its queue while still inside the loop.  This will give you the ability to have user interaction while the loop executes.  If you were to add a Cancel button for instance, your user would be more likely to be able to use it if Application.DoEvents  is in the loop.



Accepted Solution

skaykay earned 100 total points
ID: 9808354
Well, the problem is that your execution of the routine is happening in the same process as that of the main instance. And hence, until you finish the routine processing, you are blocked from doing anything. And this would be very annoying especially when the routine is a time consuming one.

The solution to this to have a separate thread of execution for the routine and call back the main thread when it completes the process. And in VB this can be achieved through ActiveX EXE and in VB.NET which supports multithreading, you can implement this by making the routine asynchronous.

Follow this link and you will find how to implement a Asynchronous component in VB.NET.

Hope this helps and I would be glad if I can help you any further.
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


Expert Comment

ID: 9811464

What about VB?

LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9813660

For VB6, just put


inside your loop.


Expert Comment

ID: 9829586

Sorry for the delay! Had been out of my work for couple of days. Well, in VB, as said, its implemented as ActiveX EXEs. Please check out my article in code project on how to implement this with VB

Will be glad to help you if required.


Expert Comment

ID: 9829604
And further FYI, DoEvents will allow the application to handle the events that are stored in the queue to be processed. This will allow you to display some status messages but will not create a Asynchronous routine.

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question