?
Solved

Program Freezes till it finishes execution

Posted on 2003-11-23
7
Medium Priority
?
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:2Angel
ID: 9811464
skaykay:

What about VB?

Thanks.
0
 
LVL 86

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

765 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