473,396 Members | 1,998 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,396 software developers and data experts.

Is there a ProcessMessages in .net?

Hi All,
Part of my new app does some quite intensive calculations. In Delphi (my
previous language) one could call Application.ProcessMessages; in the
calculation loop to make sure that the system was being given enough time to
process it's own messages (makes the app and desktop much more responsive).
Is there a similiar trick available to c# .net developers?

Thanks
RobP
'There are only 10 types of people in this world - Those that understand
binary and those that don't'
Oct 19 '06 #1
5 30572

"Rob Pollard" <ro************@hotmail.comwrote in message
news:JX*********************@fe3.news.blueyonder.c o.uk...
| Hi All,
| Part of my new app does some quite intensive calculations. In Delphi (my
| previous language) one could call Application.ProcessMessages; in the
| calculation loop to make sure that the system was being given enough time
to
| process it's own messages (makes the app and desktop much more
responsive).
| Is there a similiar trick available to c# .net developers?
|
| Thanks
| RobP
| 'There are only 10 types of people in this world - Those that understand
| binary and those that don't'
|
|

Don't rely on tricks, use a separate thread to execute long running tasks.
If you do prefer tricks, take a look at Application.DoEvents, but beware
it's a hack invented to help single threaded applications to keep the UI
responsive, stay away from it if you can.

Willy.
Oct 19 '06 #2
Thanks Willy,
I will go the multi-threaded route.

--
RobP
'There are only 10 types of people in this world - Those that understand
binary and those that don't'

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:%2***************@TK2MSFTNGP05.phx.gbl...
>
"Rob Pollard" <ro************@hotmail.comwrote in message
news:JX*********************@fe3.news.blueyonder.c o.uk...
| Hi All,
| Part of my new app does some quite intensive calculations. In Delphi
(my
| previous language) one could call Application.ProcessMessages; in the
| calculation loop to make sure that the system was being given enough
time
to
| process it's own messages (makes the app and desktop much more
responsive).
| Is there a similiar trick available to c# .net developers?
|
| Thanks
| RobP
| 'There are only 10 types of people in this world - Those that understand
| binary and those that don't'
|
|

Don't rely on tricks, use a separate thread to execute long running tasks.
If you do prefer tricks, take a look at Application.DoEvents, but beware
it's a hack invented to help single threaded applications to keep the UI
responsive, stay away from it if you can.

Willy.


Oct 19 '06 #3

Willy Denoyette [MVP] wrote:
Don't rely on tricks, use a separate thread to execute long running tasks.
If you do prefer tricks, take a look at Application.DoEvents, but beware
it's a hack invented to help single threaded applications to keep the UI
responsive, stay away from it if you can.
I can see the value in using DoEvents in simple cases that don't
warrant the complexity of threading. It works fine as long as you
disable your UI buttons to prevent reentrancy into your OnClick event
handlers.

Sometimes the best and most elegant solutions don't make sense in a
simple and small app. I do this kind of thing in small utility programs
that are mostly single-purpose in nature.

And this is an attractive option if you're porting code from Delphi and
you don't want to re-invent the wheel. But this may also be a good time
to revisit the program's architecture, especially if this is an
important program that is a key part of a production system.

That's just my opinion, of course.

Eric

Oct 19 '06 #4
Hello Willy Denoyette [MVP],

I disagree with Application.Doevents being a hack. Creating a separate thread
for a trivial calculation seems like overkill to me. Of course now in .Net
spawning a separate thread is easier, but I still think Application.Doevent
can help you in a lot of situation, and you shouldn't be stopped from using
it if you observe that the effect works for you.

Regards
Cyril Gupta

You can do anything with a little bit of 'magination.
I have been programming so long, that my brain is now soft-ware.
http://www.cyrilgupta.com/blog
"Rob Pollard" <ro************@hotmail.comwrote in message
news:JX*********************@fe3.news.blueyonder.c o.uk...
| Hi All,
| Part of my new app does some quite intensive calculations. In
Delphi (my
| previous language) one could call Application.ProcessMessages; in
the
| calculation loop to make sure that the system was being given enough
time
to
| process it's own messages (makes the app and desktop much more
responsive).
| Is there a similiar trick available to c# .net developers?
|
| Thanks
| RobP
| 'There are only 10 types of people in this world - Those that
understand
| binary and those that don't'
|
|
Don't rely on tricks, use a separate thread to execute long running
tasks. If you do prefer tricks, take a look at Application.DoEvents,
but beware it's a hack invented to help single threaded applications
to keep the UI responsive, stay away from it if you can.

Willy.

Oct 19 '06 #5
Well it looks like we will have to agree to disagree, I keep calling it a
hack, I never used it in production code.
You simply have to ask yourself why you ever would call DoEvents, given you
know the dangers of DoEvents, because there are almost always better
alternatives.

For tivial calculations you can use anonymous delegates like this:

private void someButton_Click(object sender, EventArgs e)
{
new Thread(delegate()
{
Thread.CurrentThread.IsBackground = true;
// long running calculation here
// update UI when needed, but remember you need to delegate the
call to the UI thread!
}).Start();
}
Nothing complicated, and I don't see it as overkill, it nicely separates the
UI thread tasks from your other application tasks.
The only time I would ever call DoEvents is when I have COM STA objects
running in a thread of a non windows application (remember STA's need to
pump the queue), but even then, there are better alternatives when running
managed code.

Willy.

"Cyril Gupta" <cy***@nospam.comwrote in message
news:a9*************************@msnews.microsoft. com...
| Hello Willy Denoyette [MVP],
|
| I disagree with Application.Doevents being a hack. Creating a separate
thread
| for a trivial calculation seems like overkill to me. Of course now in .Net
| spawning a separate thread is easier, but I still think
Application.Doevent
| can help you in a lot of situation, and you shouldn't be stopped from
using
| it if you observe that the effect works for you.
|
| Regards
| Cyril Gupta
|
| You can do anything with a little bit of 'magination.
| I have been programming so long, that my brain is now soft-ware.
| http://www.cyrilgupta.com/blog
|
| "Rob Pollard" <ro************@hotmail.comwrote in message
| news:JX*********************@fe3.news.blueyonder.c o.uk...
| | Hi All,
| | Part of my new app does some quite intensive calculations. In
| Delphi (my
| | previous language) one could call Application.ProcessMessages; in
| the
| | calculation loop to make sure that the system was being given enough
| time
| to
| | process it's own messages (makes the app and desktop much more
| responsive).
| | Is there a similiar trick available to c# .net developers?
| |
| | Thanks
| | RobP
| | 'There are only 10 types of people in this world - Those that
| understand
| | binary and those that don't'
| |
| |
| Don't rely on tricks, use a separate thread to execute long running
| tasks. If you do prefer tricks, take a look at Application.DoEvents,
| but beware it's a hack invented to help single threaded applications
| to keep the UI responsive, stay away from it if you can.
| >
| Willy.
| >
|
|
Oct 19 '06 #6

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

Similar topics

3
by: Alexander van Meerten | last post by:
Hello, I have to make an application that works on pc and apple mac. Therefore I am investigating if it's possible to use html/javascript. The database has 10000 records and is sequentially...
21
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
7
by: Torbjørn Morka | last post by:
I am currently working with a small program using BCB 6, and this is my question. When clicking the button the code is this...:...
2
by: Jerry S | last post by:
Hi A beginner's question. I want to run through a series of instructions over and over until a user hits a button. What's the standard way of making the application process user input...
19
by: C# Learner | last post by:
What's a nice way to create a non-blocking pause in execution? Will I need to use some kind of timer for this, or is there a nicer way?
2
by: Tales Normando | last post by:
Hi, Elighten me what's wrong, please. I'm working on a project that uses 2 programs, a client and a server. The server must remote a message exchange class to provide communication between...
10
by: Ricardo Luceac | last post by:
Hi all. I'm having a problem with this, I have look if a file exists, if don't wait till it is created and if it exists I need to open it. I do the following: for (; ; ) {
2
by: rcp | last post by:
Hi all, I've read all posts from all existing threads and none of them worked to solve my problem, although its exactly the same. I'll try to explain my case and see if a kind soul could help me...
4
JustRun
by: JustRun | last post by:
Hi All, I'm developing a windows desktop solution using VC# , I deal with my database using Dataset. My Problem that i'm trying to call a Form to display a confirmation message after every...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.