Solved

Program Freezes till it finishes execution

Posted on 2003-11-23
7
302 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 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
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!

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

734 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