473,763 Members | 3,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DoEvents() "Hangs"

Group:

We have an application that is calling a stored proc. The stored proc
takes anywhere from 15 to 90 minutes to run.

In order to keep the GUI responsive, we are using a BackgroundWorke r to
actually make the call to the stored proc. The app then sits in a loop
that awakes every second and updates an elapsed time value.

The problem that we are having is that after a certain period of time -
which is rarely the same amount - the call to DoEvents hangs (does not
return).

I was hoping the group could help us with: a) why thiat might be
occuring and b) what if anything can be done to fix it.

Here's the key areas of the code:

This is from the method that starts the ball rolling:
Aug 3 '06 #1
15 6021
Hello ce******@ocv.co m,

Do people really still use DoEvents() (is it even valid in C#?). You should
be using Thread.Join or Thread.Sleep (or a synchronization semantic like
a Mutex or Monitor).
Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
http://adoguy.com
Group:

We have an application that is calling a stored proc. The stored proc
takes anywhere from 15 to 90 minutes to run.

In order to keep the GUI responsive, we are using a BackgroundWorke r
to actually make the call to the stored proc. The app then sits in a
loop that awakes every second and updates an elapsed time value.

The problem that we are having is that after a certain period of time
- which is rarely the same amount - the call to DoEvents hangs (does
not return).

I was hoping the group could help us with: a) why thiat might be
occuring and b) what if anything can be done to fix it.

Here's the key areas of the code:

This is from the method that starts the ball rolling:
.
.
.
case "Consolidat e Revenue": {
bgwThread.RunWo rkerAsync( cConsolidateRev enue );
SleepAndUpdate( );
break;
}
.
.
.
This is from the "DoWork" event handler:

private void bgwThread_DoWor k( object sender, DoWorkEventArgs e )
{
switch ((int)e.Argumen t) {
case cConsolidateRev enue: {
ConsolidateReve nue( cn, dtPickerStartDa te.Value.Date,
dateImportEndDa te );
break;
}
.
.
.
Here is SleepAndUpdate:
private void SleepAndUpdate( ) {
while (notDone) {
ShowElapsedTime ();
Application.DoE vents();
System.Threadin g.Thread.Sleep( 1000 );
}
}
We have verfied that the app is indeed haning on the call to
DoEvents()

Thank you for your help

Aug 3 '06 #2
Why are you having the front end stop if you are running the operation on a
background thread anyways?

Couldn't you just make the background thread tell the front end when it is
done through a callback/event/etc

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

<ce******@ocv.c omwrote in message
news:11******** **************@ 75g2000cwc.goog legroups.com...
Group:

We have an application that is calling a stored proc. The stored proc
takes anywhere from 15 to 90 minutes to run.

In order to keep the GUI responsive, we are using a BackgroundWorke r to
actually make the call to the stored proc. The app then sits in a loop
that awakes every second and updates an elapsed time value.

The problem that we are having is that after a certain period of time -
which is rarely the same amount - the call to DoEvents hangs (does not
return).

I was hoping the group could help us with: a) why thiat might be
occuring and b) what if anything can be done to fix it.

Here's the key areas of the code:

This is from the method that starts the ball rolling:
.
.
.
case "Consolidat e Revenue": {
bgwThread.RunWo rkerAsync( cConsolidateRev enue );
SleepAndUpdate( );
break;
}
.
.
.

This is from the "DoWork" event handler:

private void bgwThread_DoWor k( object sender, DoWorkEventArgs e ) {
switch ((int)e.Argumen t) {
case cConsolidateRev enue: {
ConsolidateReve nue( cn, dtPickerStartDa te.Value.Date,
dateImportEndDa te );
break;
}
.
.
.

Here is SleepAndUpdate:
private void SleepAndUpdate( ) {
while (notDone) {
ShowElapsedTime ();
Application.DoE vents();
System.Threadin g.Thread.Sleep( 1000 );
}
}
We have verfied that the app is indeed haning on the call to DoEvents()

Thank you for your help

Aug 3 '06 #3
The business requirements are such that the call needs to be
synchronous but the GUI needs to be semi-responsive while it is
running.

The users are not able to perform any other taks in the app while the
call is being processed but when the process is long running they
don't want the screen to "white" out either.

That is the only reason for the threading.

Aug 3 '06 #4
Then you need to just disable the GUI programmiticall y. Thread.Sleep()
on the UI thread is never correct. Look into using the BackgroundWorke r
class for a simple and sound solution if you're using 2.0.

http://msdn2.microsoft.com/en-us/lib...undworker.aspx

ce******@ocv.co m wrote:
The business requirements are such that the call needs to be
synchronous but the GUI needs to be semi-responsive while it is
running.

The users are not able to perform any other taks in the app while the
call is being processed but when the process is long running they
don't want the screen to "white" out either.

That is the only reason for the threading.
Aug 3 '06 #5
Exactly, I am using the BackgroundWorke r (see code snippets) above. In
essence, I am firing off the stored proc and then putting the GUI in a
loop that sleeps for a while, awakens, and updates itself and then goes
back to sleep. This continues until the stored proc returns.

But the trouble is that it (the SleepAndUpdate loop) stops working
after a while. When it first fires up, everything is great and then
after an indeterminate period of time the DoEvents() stops returning.

It is puzzling.

I hate to take the "easy" way out and point to the framework but that
is indeed what it seems like the trouble is.

All helpful thoughts and suggestions (not the snarky ones about "Do
people really still use DoEvents() (is it even valid in C#?).") are
appreciated.

wf****@gmail.co m wrote:
Then you need to just disable the GUI programmiticall y. Thread.Sleep()
on the UI thread is never correct. Look into using the BackgroundWorke r
class for a simple and sound solution if you're using 2.0.

http://msdn2.microsoft.com/en-us/lib...undworker.aspx
Aug 3 '06 #6
Don't sleep on the UI thread. Ever. You're preventing the UI
thread from processing any messages for 1 second. Disable the main form
and its controls or launch another simple modal form to actually launch
the processing thread and display some sort of "I'm running" indicator
until it receives notification (not by polling, by callback) that the
thread has finished.
Your implementation is broken, not the framework. This is not meant
to be snarky, just straightforward .

ce******@ocv.co m wrote:
Exactly, I am using the BackgroundWorke r (see code snippets) above. In
essence, I am firing off the stored proc and then putting the GUI in a
loop that sleeps for a while, awakens, and updates itself and then goes
back to sleep. This continues until the stored proc returns.

But the trouble is that it (the SleepAndUpdate loop) stops working
after a while. When it first fires up, everything is great and then
after an indeterminate period of time the DoEvents() stops returning.

It is puzzling.

I hate to take the "easy" way out and point to the framework but that
is indeed what it seems like the trouble is.

All helpful thoughts and suggestions (not the snarky ones about "Do
people really still use DoEvents() (is it even valid in C#?).") are
appreciated.

wf****@gmail.co m wrote:
Then you need to just disable the GUI programmiticall y. Thread.Sleep()
on the UI thread is never correct. Look into using the BackgroundWorke r
class for a simple and sound solution if you're using 2.0.

http://msdn2.microsoft.com/en-us/lib...undworker.aspx
Aug 3 '06 #7
wfa:

Sorry, I wasn't indicting you. I just get frustrated with condescending
posts.

In any case, the issue is that when the call returns then we must move
onto the next step in the process. We let the stored proc run in the
back ground BUT we can't continue on with processing until the stored
proc returns. That is why we go into a sleep loop. Otherwise, we just
loop until the semaphore is reset.

wfa...@gmail.co m wrote:
Don't sleep on the UI thread. Ever. You're preventing the UI
thread from processing any messages for 1 second. Disable the main form
and its controls or launch another simple modal form to actually launch
the processing thread and display some sort of "I'm running" indicator
until it receives notification (not by polling, by callback) that the
thread has finished.
Your implementation is broken, not the framework. This is not meant
to be snarky, just straightforward .
Aug 3 '06 #8
I agree with this completely.

You can just leave the UI doing nothing and wait on an event from the worker
thread (i.e. with a modal dialog). This is a quite common task (and many
people include "cancel" buttons on such a screen so the user can stop what
they are doing).

Personally I would also question the business requirement of having a user
on the system unable to use their interface for 15-90 minutes as this sounds
exactly like the type of job that should be done by some system service. By
putting the requirement that the person can't do anything when this is
happenning also leads directly to the conclusion that noone can be doing
anything while this happens on the database (or atleast touching the same
data).

Cheers,

Greg

<wf****@gmail.c omwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Don't sleep on the UI thread. Ever. You're preventing the UI
thread from processing any messages for 1 second. Disable the main form
and its controls or launch another simple modal form to actually launch
the processing thread and display some sort of "I'm running" indicator
until it receives notification (not by polling, by callback) that the
thread has finished.
Your implementation is broken, not the framework. This is not meant
to be snarky, just straightforward .

ce******@ocv.co m wrote:
>Exactly, I am using the BackgroundWorke r (see code snippets) above. In
essence, I am firing off the stored proc and then putting the GUI in a
loop that sleeps for a while, awakens, and updates itself and then goes
back to sleep. This continues until the stored proc returns.

But the trouble is that it (the SleepAndUpdate loop) stops working
after a while. When it first fires up, everything is great and then
after an indeterminate period of time the DoEvents() stops returning.

It is puzzling.

I hate to take the "easy" way out and point to the framework but that
is indeed what it seems like the trouble is.

All helpful thoughts and suggestions (not the snarky ones about "Do
people really still use DoEvents() (is it even valid in C#?).") are
appreciated.

wf****@gmail.co m wrote:
Then you need to just disable the GUI programmiticall y. Thread.Sleep()
on the UI thread is never correct. Look into using the BackgroundWorke r
class for a simple and sound solution if you're using 2.0.

http://msdn2.microsoft.com/en-us/lib...undworker.aspx

Aug 3 '06 #9
Have the background thread notify the foreground thread when it is complete
.....

Also you can't continue with the process involving the sproc but can you do
other things while waiting or is the app designed to only do this one
process and the one process doesn't make sense to be doing multiples (i.e.
running a big report).

Cheers,

Greg
<ce******@ocv.c omwrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
wfa:

Sorry, I wasn't indicting you. I just get frustrated with condescending
posts.

In any case, the issue is that when the call returns then we must move
onto the next step in the process. We let the stored proc run in the
back ground BUT we can't continue on with processing until the stored
proc returns. That is why we go into a sleep loop. Otherwise, we just
loop until the semaphore is reset.

wfa...@gmail.co m wrote:
>Don't sleep on the UI thread. Ever. You're preventing the UI
thread from processing any messages for 1 second. Disable the main form
and its controls or launch another simple modal form to actually launch
the processing thread and display some sort of "I'm running" indicator
until it receives notification (not by polling, by callback) that the
thread has finished.
Your implementation is broken, not the framework. This is not meant
to be snarky, just straightforward .

Aug 3 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1180
by: Roger Espinosa | last post by:
I'm attempting to install dbxml-1.10 on OS X 10.2.8 (gcc3.x prerelease, Python 2.3.2 built on same), and while everything builds happily, when I try to invoke import dbxml Python just ... hangs. I haven't been able to find this problem described (there are matches for "popen" hanging, but the advice doesn't seem to apply here).
1
2661
by: Vivien Mallet | last post by:
Hello, I use popen2.Popen4 and I experienced problems with it. Let me show you with an example. The following script is called "lines" (it prints lines of 'X'): --------------------- #!/usr/bin/env python import sys
0
1650
by: David H | last post by:
Background. I'm running on WinXP w/ MS Services for Unix installed (to give rsh/rlogin ability), both Python 2.3 and 2.4 version. In linux, I'm running RHEE with python2.3 version. The code below works fine for me in linux, but in WinXP the popen*() command "hangs". More specifically, I get an apparent python prompt (without the '>>> ', but whatever I type has no effect, and hitting return does a CR but not the additional LF, so I...
1
3155
by: szudor | last post by:
Hi, When I start db2cc, the program hangs with memory access violation in javaw.exe. Strating with trace option, in java trace file I found the following information: 0SECTION TITLE subcomponent dump routine NULL =============================== 1TISIGINFO signal 11 received 1TIDATETIME Date: 2005/08/29 at 08:04:16
3
2497
by: Johnny M | last post by:
using Access 2003 Pardon the subject line, but I don't have a better word for this strange behavior (or behavior I don't understand!!!) I have a class module named DepreciationFactor. One of the properties is a follows (irrelevant code omitted):
1
3834
by: happyinst | last post by:
I have recently added some code to a web application and now I find it hanging after I do about 2 or 3 postbacks within the application. It hangs after doing different things (I cannot find anything in common) and when I run in Debug mode, it doesn't even appear to be within my code when it hangs (I put breakpoints all over the place and it doesn't stop at any of them during the hang). It hangs after I click a button on the page... but...
3
3084
by: Wardeaux | last post by:
All, I've written a "setup" wrapper that calls a sequence of "setup.exe", and all works except when I call the setup.exe for the MSDE, then it gets about half way through and then hangs... The MSDE setup works fine from a CMD prompt... anyone know of articles or known issues with this technique, and what are my alternatives to having my user install several "Commandline parameter intensive" setups to get this installed? :) MTIA wardeaux
4
2592
by: dumbkiwi | last post by:
I have written a script that uses the urllib2 module to download web pages for parsing. If there is no network interface, urllib2 hangs for a very long time before it raises an exception. I have set the socket timeout with socket.setdefaulttimeout(), however, where there is no network interface, this seems to be ignored - presumably, because without a network interface, there is nothing for the socket module to interact with.
5
3125
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I have been using the Click Once deployment feature of VS2005 - very nice. I had IE6 at the time when I started using Click Once Deployment, and everything worked fine. But then my workstation got upgraded to IE7, and now whenever I deploy an application and IE7 comes up for the Install page - it just says "Connecting..." and just hangs, and then I have to manually end the program. I did not have this problem with IE6. Are...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.