[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Program Freezes till it finishes execution

Posted on 2003-11-23
7
Medium Priority
?
307 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 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

873 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