Solved

Program Freezes till it finishes execution

Posted on 2003-11-23
7
299 Views
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!!
0
Comment
Question by:wireframe9
7 Comments
 
LVL 1

Expert Comment

by:anaadoul
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
0
 
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

Application.DoEvents

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.

Regards,

Idle_Mind
0
 
LVL 4

Accepted Solution

by:
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.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/asyncui.asp

Hope this helps and I would be glad if I can help you any further.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 2

Expert Comment

by:2Angel
ID: 9811464
skaykay:

What about VB?

Thanks.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9813660
2Angel,

For VB6, just put

DoEvents

inside your loop.

Idle_Mind
0
 
LVL 4

Expert Comment

by:skaykay
ID: 9829586
Hi!!

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

http://www.codeproject.com/vbscript/AsyncSample.asp

Will be glad to help you if required.

Cheers,
skaykay!
0
 
LVL 4

Expert Comment

by:skaykay
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.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 84
Windows Script Host failed (Access is denied.) error 6 145
Excel - Save a copy of work book 13 84
Protecting vb6 & .Net code Obfuscation 18 121
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

808 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