473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Button click - form update?

So another simple question from me :)

as im working away ive made a button that does a series of wonderful
things.. and as it goes along it suppose to update a label to let the user
know what stage its at... but.. the rendering isnt done until after the code
is completed... how do i tell it to render so that the label gets updated?

Thanks
Justin
Sep 11 '07 #1
8 1708
Nicholas Paldino [.NET/C# MVP] wrote:
Justin,

The short answer, call the static DoEvents method on the Application
class in the System.Windows.Forms namespace.
IMHO, DoEvents() is the last option anyone should choose for addressing
this sort of thing, and as such it's definitely not what ought to be
proposed as the first answer, even if it happens to be short.

It's simple to implement, but BackgroundWorker and similar solutions
aren't actually all that hard, and are much more appropriate ways of
dealing with the issue. It's such a basic issue in .NET (and Windows
programming more generally), to know how to move lengthy processing out
of the main UI thread, that once a person runs into it they should just
go ahead and learn how to do it right.

Pete
Sep 11 '07 #2
Hi,

"Justin Rich" <jr******@yahoo.spam.comwrote in message
news:e2****************@TK2MSFTNGP03.phx.gbl...
So another simple question from me :)

as im working away ive made a button that does a series of wonderful
things.. and as it goes along it suppose to update a label to let the user
know what stage its at... but.. the rendering isnt done until after the
code is completed... how do i tell it to render so that the label gets
updated?
What if you do your processing (that seems to be a time consuming opertion)
in a separate thread?

Then you can use Control.Invoke to update the UI
Sep 11 '07 #3
Doug Semler wrote:
Subtle? Call DoEvents in Windows message event handler that updates a
second control right before the DoEvents() call. That second control
has an event handler that updates a the first control right before a
DoEvents() call. Convince original programmer to do work in
background thread. All well. Except original programmer now accesses
the form controls from background thread. Cannot convince original
programmer that this is not good.
Nicholas did specifically say for the access from the background thread
to be done via a call to Invoke(), which is a correct and perfectly
acceptable way to interact with form controls from a background thread.

Why would you want to convince anyone that "this is not good"?

I agree (obviously) that DoEvents() is not the right solution, but I
don't really understand the rest of your reply. One one decides not to
use DoEvents(), that necessarily implies moving the code to another
thread, and if the code exists in another thread it will necessarily
have to somehow interact with the form controls from that thread if
those controls are to be updated with respect to the work in the thread.

Doing that isn't a problem at all, as long as it's done correctly.

Pete
Sep 11 '07 #4
sounds good to me.. where do i learn?
"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13*************@corp.supernews.com...
Nicholas Paldino [.NET/C# MVP] wrote:
>Justin,

The short answer, call the static DoEvents method on the Application
class in the System.Windows.Forms namespace.

IMHO, DoEvents() is the last option anyone should choose for addressing
this sort of thing, and as such it's definitely not what ought to be
proposed as the first answer, even if it happens to be short.

It's simple to implement, but BackgroundWorker and similar solutions
aren't actually all that hard, and are much more appropriate ways of
dealing with the issue. It's such a basic issue in .NET (and Windows
programming more generally), to know how to move lengthy processing out of
the main UI thread, that once a person runs into it they should just go
ahead and learn how to do it right.

Pete

Sep 11 '07 #5
I agree, I would never use DoEvents, but some people just want the quick
and dirty solution.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13*************@corp.supernews.com...
Nicholas Paldino [.NET/C# MVP] wrote:
>Justin,

The short answer, call the static DoEvents method on the Application
class in the System.Windows.Forms namespace.

IMHO, DoEvents() is the last option anyone should choose for addressing
this sort of thing, and as such it's definitely not what ought to be
proposed as the first answer, even if it happens to be short.

It's simple to implement, but BackgroundWorker and similar solutions
aren't actually all that hard, and are much more appropriate ways of
dealing with the issue. It's such a basic issue in .NET (and Windows
programming more generally), to know how to move lengthy processing out of
the main UI thread, that once a person runs into it they should just go
ahead and learn how to do it right.

Pete

Sep 11 '07 #6
On Sep 11, 1:48 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
Doug Semler wrote:
Subtle? Call DoEvents in Windows message event handler that updates a
second control right before the DoEvents() call. That second control
has an event handler that updates a the first control right before a
DoEvents() call. Convince original programmer to do work in
background thread. All well. Except original programmer now accesses
the form controls from background thread. Cannot convince original
programmer that this is not good.

Nicholas did specifically say for the access from the background thread
to be done via a call to Invoke(), which is a correct and perfectly
acceptable way to interact with form controls from a background thread.

Why would you want to convince anyone that "this is not good"?

I agree (obviously) that DoEvents() is not the right solution, but I
don't really understand the rest of your reply. One one decides not to
use DoEvents(), that necessarily implies moving the code to another
thread, and if the code exists in another thread it will necessarily
have to somehow interact with the form controls from that thread if
those controls are to be updated with respect to the work in the thread.

Doing that isn't a problem at all, as long as it's done correctly.

Pete
Missed a word: Accesses controls directly...Without Invoke().....and
because it has worked without Invoke() in the past it is difficult to
convince that it is wrong.

Sep 11 '07 #7
Doug Semler wrote:
Missed a word: Accesses controls directly...Without Invoke().....and
because it has worked without Invoke() in the past it is difficult to
convince that it is wrong.
Ah. Yes, that's a significant difference in meaning. :) And yes, I
agree it can sometimes be hard to convince someone that just because it
worked without using Invoke() before, that doesn't mean failing to use
Invoke() is correct.

Much better to indoctrinate new .NET programmers from the outset. :)

Thanks for clarifying.

Pete
Sep 11 '07 #8
Justin Rich wrote:
Actually where I ran in to the problem is with a webpart that uses a web
service.
[...]

probably something i should direct more to the WSS dev newsgroup.. but i
figured there would be some value in knowing this anyways.
A web-specific newsgroup would probably be more useful, yes. I don't
actually know all of the ways that the web components differ from
regular forms. But I know that they do, and for sure the general
updating mechanisms are likely to be quite different, given all of the
overhead involved in dynamically updating a web page (especially from
server-side code) versus doing so in a local-only forms application.

Pete
Sep 11 '07 #9

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

Similar topics

13
by: Samantha Smit | last post by:
Hi, I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this: http://MyServer.com/Update.asp?UserName=Tom My asp code is...
6
by: Rod Snyder | last post by:
I'm trying to set up a page with an asp.net link button that would send a user to a certain page and on page load execute a specific stored procedure tied to the button on the previous page. The...
1
by: Klaus Jensen | last post by:
Hi! This has been annoying me all day, and I can't get it to work It is really driving me nuts! Basicly this simple webapp created to illustrate my problem, renders five buttons, and adds a...
4
by: David Colliver | last post by:
Hi all, I am having a slight problem that hopefully, someone can help me fix. I have a form on a page. Many items on the form have validation controls attached. Also on this form are...
11
by: Neo Geshel | last post by:
Greetings. Hopefully someone will be able to untie this Gordian Knot I have found myself bound up in. I am trying to add a submit button dynamically to a PlaceHolder. This button will help...
9
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
11
by: cindy | last post by:
I have a form, has javascript registered so a modal pops up. Button click will close form. Now I need to do an update with modal form data before it closes. I can put a second button and register...
1
by: Joey | last post by:
I have an asp.net 1.1/C# web form with a text box server control and one button server control. Users can type in text to search and then click the button to start the search. I want them to be...
6
by: Paul Furman | last post by:
I'm getting incorrect response when hitting the enter key instead of actually clicking the button on a form. It activates but the post data isn't being sent I think. The php generated page...
1
by: dipalichavan82 | last post by:
i have a form on which i m displaying data in datagridview.on same form i have update ,insert,delete button.when i click on insert or update btn new form opens with controls(textbox) in which user is...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.