473,771 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Long Process

I have a long process I run that needs to be complete before the user can continue. I can change the cursor to an hourglass, but I want to update the Status Strip on the bottom during the process. I set the statusstrip label to "Downloading... ", but it will not show up on the form. I need to display this message before it starts the process. I can put a thread.sleep for 1 second after I do the initial process, but that seems sloppy to me. Any suggestions? Here is my code launched from a button click:
'update the label--This does not show because the process starts before the UI updates
slDBList.Text = "Retrieving Databases..."Tr yMe.Cursor = Cursors.WaitCur sorDim lstServers As List(Of String)'set to false in case of an error boolServersLoad ed = FalseboolDBLoad ed = False'clear the servers list cbServers.DataS ource = Nothing'clear the databases list dbDatabases.Dat aSource = NothingIf chkSort.Checked = True ThenlstServers = GetSqlServers(T rue)ElselstServ ers = GetSqlServers(F alse)End IfcbServers.Dat aSource = lstServers'set to true to enabled the selected index change on the dropdown boolServersLoad ed = TrueslDBList.Te xt = ""Catch ex As ExceptionMessag eBox.Show("Erro r loading server list. Error: " & ex.ToString, "Data Error", MessageBoxButto ns.OK, MessageBoxIcon. Error)boolServe rsLoaded = FalseslDBList.T ext = ""FinallyMe.Cur sor = Cursors.ArrowEn d Try
Jun 27 '08
32 1707
"Joergen Bech @ post1.tele.dk>" <jbech<NOSPAMNO SPAMschrieb
>>(But I see it as your agreement supplemented by the BGW)

I'll pretend that additional information was my excuse for
posting it and saves some face.
No problem. Everything's fine. Even the whether. :)
Armin
Jun 27 '08 #21
No problem. Everything's fine. Even the whether. :)

"whether".Repla ce("whether", "weather")

;-)

Jun 27 '08 #22
Whether or not the wether has been out in the weather, it will still be just
fine with mint sauce.

Figure that one out :)
"Armin Zingler" <az*******@free net.dewrote in message
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
>No problem. Everything's fine. Even the whether. :)

"whether".Repla ce("whether", "weather")

;-)
Jun 27 '08 #23
Yes

"Armin Zingler" <az*******@free net.deschreef in bericht
news:%2******** **********@TK2M SFTNGP06.phx.gb l...
"Cor Ligthert[MVP]" <no************ @planet.nlschri eb
>Joergen,

Be aware that you never should do what you advice as it is a
critical process that has to be completed, and the user can end that
in the middle without knowing what is the effect.

Think by instance in a paying process by banks, were steps have to
be done, I would never be the one who would give an advice as yours.

Just my idea,

Cor

Like Joergen, I don't understand this plea. Using another thread to avoid
the UI thread being blocked is the (only) right action, IMO. But maybe you
meant that the UI thread also have to be in an appropriate state depending
on the whole situation, where I would agree.
Armin
Jun 27 '08 #24
If DoEvents should not be used any more, why is it in the language?

application.doe vents

That's the quickest way to get a control updated. Works just fine. This
is the first I have heard about it not being valid any longer. Does
Microsoft know about this?

Mike

On Thu, 22 May 2008 11:09:12 +0200, in
microsoft.publi c.dotnet.langua ges.vb "Armin Zingler"
<az*******@free net.dewrote:
>"Mayur H Chauhan" <ma***@orioninc .comschrieb
>How about Application.DoE vents ? This might help for processing
pending thread.

Doevents should not be used anymore. It was valid with previous VB
versions where multi threading was (appart from appartment threading)
almost impossible. Doevents creates more problems than necessary. First,
the classification of UI tasks and independent other tasks would have to
be removed. Not every task has an abstract and regular event/callback
mechanism that can be used to update the UI, especially when talking
about long running database activities. In addition, you'd have
to be aware of code reentrance. Moreover, why create new code to process
messages even if there is already a message loop that is made for it? My
experience is that almost every time when I was using Doevents, 5 LOC
later I'd wished to go the "clean" way and had used a separate thread
instead.
Armin
Jun 27 '08 #25

There are many language features coming from VB6 that have found
a new home at the core of the framework because that is where they
belong rather than just in the Microsoft.Visua lBasic namespace.

Leaving it out would mean one more thing preventing many VB6
applications from being ported to .Net.

What DoEvents does could be achieved with other languages
as well - including non-Microsoft languages before .Net.

It is still a bad practice for all the reasons discussed in this
thread (and more).

If you, say, google for discussions about how to accomplish the
same thing in Java, the discussions usually go along this line:

- a) Is there something similar to DoEvents in Java?
- b) What the heck is DoEvents and why do you need it?
- a) (explains)
- b) Don't do that. Do it this way ...

Regards,

Joergen Bech

On Thu, 22 May 2008 21:29:55 -0700, Ju********@home .net wrote:
>If DoEvents should not be used any more, why is it in the language?

application.do events

That's the quickest way to get a control updated. Works just fine. This
is the first I have heard about it not being valid any longer. Does
Microsoft know about this?

Mike

On Thu, 22 May 2008 11:09:12 +0200, in
microsoft.publ ic.dotnet.langu ages.vb "Armin Zingler"
<az*******@fre enet.dewrote:
>>"Mayur H Chauhan" <ma***@orioninc .comschrieb
>>How about Application.DoE vents ? This might help for processing
pending thread.

Doevents should not be used anymore. It was valid with previous VB
versions where multi threading was (appart from appartment threading)
almost impossible. Doevents creates more problems than necessary. First,
the classification of UI tasks and independent other tasks would have to
be removed. Not every task has an abstract and regular event/callback
mechanism that can be used to update the UI, especially when talking
about long running database activities. In addition, you'd have
to be aware of code reentrance. Moreover, why create new code to process
messages even if there is already a message loop that is made for it? My
experience is that almost every time when I was using Doevents, 5 LOC
later I'd wished to go the "clean" way and had used a separate thread
instead.
Armin
Jun 27 '08 #26
<Ju********@hom e.netschrieb
If DoEvents should not be used any more, why is it in the language?
I should have added that is only my opinion. However, not only mine.
(does this make sense?)

From an objective point of view, DoEvents is not an evil thing. However,
be very careful using it, and live with the drawbacks mentioned. After
writing dozends of paragraphs, assuming that DoEvents is, as you write,
is "in the language", I remember that it isn't because it's not in the
MSVB namespace. Therefore, long story short:

- Thinking in VB6 times usually didn't include the opportunity of
multiple threads. (again, appartment threading left out). Therefore,
DoEvents was the solution for what it does.

- Thinking now, my brain works this way: I have to put a task anywhere
in the code. Every task is executed in a thread. I wonder: In which
thread do I want to execute it? Well, I have a UI thread, but as I want
it to talk to the user and accept it's input, I don't recognize this
thread as the right one to put my task in. I decide to put it into a new
thread. So, I never come to the point that forces me to use DoEvents.
The different way of thinking because of taking into account free
threading as a matter of course (right words?), causes that I do not
have to use DoEvents anymore. Managing tasks and threads got a very high
priority now. As a consequence, I call DoEvents obsolete.

application.doe vents

That's the quickest way to get a control updated. Works just fine.
That was even the wrong way in VB6. Also often written in the VB6 groups
in the past. To update a control, call it's Refresh method. DoEvents
processes *all* messages in the message queue. So, to process one
message, process all messages? Naah. In 90% (no, I didn't count) people
weren't aware of the fact that, e.g., the user will be able to press
Alt+F4 to close the Form while using Doevents. Usually the app crashes
then. (I don't say that using multiple threads is easier to handle.)
This is the first I have heard about it not being valid any longer.
Does Microsoft know about this?
I haven't met him yet. ;-)
Armin

Jun 27 '08 #27
One main thing I forgot:
Imagine you put the work in the UI thread and use Doevents. Everything
works fine. Now you want to do an additional job at the same time. How
will you handle all this in the UI thread? How can you switch between
the three tasks (UI, job 1, job 2) all within the same thread?

Maybe you say: Then it's time for another thread. I'd answer: Which of
the jobs (job1 or job2) runs in the UI thread and which one in a
separate thread? I guess you wouldn't have an answer. Therefore I always
suggest: Have the UI thread only do the things that it's name says. (I
personally accept an unresponsive UI only for few seconds, apart from
heavy and unavoidable UI updates (and apart from some tools I wrote for
my own joy only))
Armin

Jun 27 '08 #28
Sorry, me again... :-(

Could have been written so basic and simple:
If I have to do two things at the same time, I put them into separate
threads instead of alternately doing them in the same thread. Therefore,
no doevents required.

Jun 27 '08 #29
Armin Zingler wrote:
<Ju********@hom e.netschrieb
From an objective point of view, DoEvents is not an evil thing.

DoEvents processes *all* messages in the message queue.
There was one good use of DoEvents, as I remember. You could disable a form, or
a toolbar, or what have you. Then at the end of a long process, call DoEvents.
This would clear out all the clicks the user had made, without calling any click
event handlers. Then you would re-enable the form or controls. It worked well to
avoid starting something from a click the user made a while ago.
Jun 27 '08 #30

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

Similar topics

5
3372
by: PontiMax | last post by:
Hi, when I press the OK button of my dialog box a long-running task is initiated. Therefore I would like to make visible a div section right after clicking the button where a user-friendly message is displayed... How can this be done? Can I make the section visible via server-side code? Via Response.Write()? Any examples would be appreciated!
18
2210
by: Larry Herbinaux | last post by:
I'm having issues with garbage collection with my long-standing service process. If you could review and point me in the right direction it would be of great help. If there are any helpful documents that you could point me to help me control the GC, then that would be great also. The .Net GC does not cleanup memory of our service process unless it is forced to by another process that hogs memory. · GC Algorithm - This is an issue...
4
1968
by: ImSoLost | last post by:
I'm running a really long process from ASP.NET and need some help... I am making a method call when the user presses a button from my webpage, which goes into a database and parses a file. This process could exceed an hour, so the user is expected to press the button to start the process and minimize the IE window and do other work while the application is processing. Anyway, after a certain period in time, the page becomes "Page could...
1
6025
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the browser back button, it loads the progress bar again. Any solution to this?
14
23170
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So, we're looking for a way to display the page with a "please wait..." message while the process is running, and then, when the process is done, update the page with the actual results/page content. We have a page that opens another browser/page...
1
2435
by: walterbyrd | last post by:
I understand that Python has them, but PHP doesn't. I think that is because mod_php is built into apache, but mod_python is not usually in apache. If mod_python was built into apache, would python still have long running processes (LRP)? Do LRPs have to do with a Python interpreter running all the time? Or is it something else? I also understand that LRPs are the reason that shared hosting is less
4
2852
by: commander_coder | last post by:
Hello, I write a lot of CGI scripts, in Python of course. Now I need to convert some to long-running processes. I'm having trouble finding resources about the best practices to do that. I've found a lot of email discussions that say something like, "You need to educate yourself about the differences when you have long- running processes" but I've not had a lot of luck with finding things that explain the differences. I've seen some...
2
1634
by: =?Utf-8?B?QWxwaGFwYWdl?= | last post by:
Hello, I have a class MyWorker. Each time I create a new instance of MyWorker, I queue it to the ThreadPool. So, 1 MyWorker object is pooled and belongs to its thread (there can't have 2 MyWorker in 1 thread from the ThreadPool). When MyWorker is initialized or instanciate, I use an asynchronous delegate to execute a long running process (depending on users, the job can be quicker). So, this async delegate will use or create a new...
2
1799
by: =?Utf-8?B?d2R1ZGVr?= | last post by:
I have a website using windows integrated security, with anonymous access turned off. The site is used to query orders from a database and when the search takes a long time, a windows login box appears. Regardless of what login the user enters into this, it does not accept it and the user is locked out of the system. Our network team and myself have been unable to find out why this is occurring, has anyone else had a similiar problem?...
0
9619
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
10260
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...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9910
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...
1
7460
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
6712
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
5354
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
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.