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

background threads and keeping the UI painting

I am trying to do some processing on a background thread while keeping the
UI painting. However, this is a generic server side call routine - and it
needs to block until the server side call completes. So the idea is, a
server side call begins, it gets spun off on another thread to keep the UI
painting - but, the code flow cannot return to the caller until the server
side call completes, because the caller expects the data.

The only way I could find to do this, was to open a modal dialog after
spinning off the new thread to do the server call. Then the callback would
close the dialog, causing the UI thread to once again begin processing. The
callback had also set the return data, so everything worked fine.

The only problem was that every time the dialog popped open (which had an
animated image to let the user know work was happening), it would activate,
then it would close and the main form would reactivate. One logical
operation sometimes involved several server side calls - and each would pop
open the dialog and then close, resulting in a lot of flashing as the main
form deactivated then reactivated.

The dialog was the only way I could find to block the main thread, and yet
keep the UI painting, and at the same time prevent the user from clicking
anywhere back on the original form and trying to do something while in the
midst of an operation (because the dialog was modal).

Any suggestions for how to implement this kind of thing? Telling the thread
to sleep or anything of that nature does not keep the UI painting - and I'm
thinking Applicaiton.DoEvents is going to allow the user to click anywhere
and mess with things, which isn't going to work either.
Mar 19 '08 #1
4 1843
Generally you launch a background thread that does the work so that the UI
thread is kept responsive. You disable the approprirate controls so that the
user can't do something that would cause problem '(o r you can test if a
background taks is running)...

--
Patrice

"Marina Levit" <so*****@someplace.coma écrit dans le message de news:
uv****************@TK2MSFTNGP06.phx.gbl...
>I am trying to do some processing on a background thread while keeping the
UI painting. However, this is a generic server side call routine - and it
needs to block until the server side call completes. So the idea is, a
server side call begins, it gets spun off on another thread to keep the UI
painting - but, the code flow cannot return to the caller until the server
side call completes, because the caller expects the data.

The only way I could find to do this, was to open a modal dialog after
spinning off the new thread to do the server call. Then the callback would
close the dialog, causing the UI thread to once again begin processing.
The callback had also set the return data, so everything worked fine.

The only problem was that every time the dialog popped open (which had an
animated image to let the user know work was happening), it would
activate, then it would close and the main form would reactivate. One
logical operation sometimes involved several server side calls - and each
would pop open the dialog and then close, resulting in a lot of flashing
as the main form deactivated then reactivated.

The dialog was the only way I could find to block the main thread, and yet
keep the UI painting, and at the same time prevent the user from clicking
anywhere back on the original form and trying to do something while in the
midst of an operation (because the dialog was modal).

Any suggestions for how to implement this kind of thing? Telling the
thread to sleep or anything of that nature does not keep the UI painting -
and I'm thinking Applicaiton.DoEvents is going to allow the user to click
anywhere and mess with things, which isn't going to work either.

Mar 19 '08 #2
The entire application would have to be disabled as really any user
interaction could invalidate things. If the task happened to be short, it
would also look like a different type of flashing to disable/enable it. I am
fairly certain that those in charge of the look of the app are not going to
go for that, though that is an option.
"Patrice" <http://www.chez.com/scribe/wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Generally you launch a background thread that does the work so that the UI
thread is kept responsive. You disable the approprirate controls so that
the user can't do something that would cause problem '(o r you can test if
a background taks is running)...

--
Patrice

"Marina Levit" <so*****@someplace.coma écrit dans le message de news:
uv****************@TK2MSFTNGP06.phx.gbl...
>>I am trying to do some processing on a background thread while keeping the
UI painting. However, this is a generic server side call routine - and it
needs to block until the server side call completes. So the idea is, a
server side call begins, it gets spun off on another thread to keep the UI
painting - but, the code flow cannot return to the caller until the server
side call completes, because the caller expects the data.

The only way I could find to do this, was to open a modal dialog after
spinning off the new thread to do the server call. Then the callback
would close the dialog, causing the UI thread to once again begin
processing. The callback had also set the return data, so everything
worked fine.

The only problem was that every time the dialog popped open (which had an
animated image to let the user know work was happening), it would
activate, then it would close and the main form would reactivate. One
logical operation sometimes involved several server side calls - and each
would pop open the dialog and then close, resulting in a lot of flashing
as the main form deactivated then reactivated.

The dialog was the only way I could find to block the main thread, and
yet keep the UI painting, and at the same time prevent the user from
clicking anywhere back on the original form and trying to do something
while in the midst of an operation (because the dialog was modal).

Any suggestions for how to implement this kind of thing? Telling the
thread to sleep or anything of that nature does not keep the UI
painting - and I'm thinking Applicaiton.DoEvents is going to allow the
user to click anywhere and mess with things, which isn't going to work
either.


Mar 19 '08 #3
Can't you keep the dialogue open until all the transactions have completed?

Instead of creating a dialogue each time you kick off a thread, open a
dialogue which then handles all the transactions in one go?

--

Rich

http://www.badangling.com
....talking pollocks since 1996

"Marina Levit" <so*****@someplace.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
The entire application would have to be disabled as really any user
interaction could invalidate things. If the task happened to be short, it
would also look like a different type of flashing to disable/enable it. I
am fairly certain that those in charge of the look of the app are not
going to go for that, though that is an option.
"Patrice" <http://www.chez.com/scribe/wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>Generally you launch a background thread that does the work so that the
UI thread is kept responsive. You disable the approprirate controls so
that the user can't do something that would cause problem '(o r you can
test if a background taks is running)...

--
Patrice

"Marina Levit" <so*****@someplace.coma écrit dans le message de news:
uv****************@TK2MSFTNGP06.phx.gbl...
>>>I am trying to do some processing on a background thread while keeping
the UI painting. However, this is a generic server side call routine -
and it needs to block until the server side call completes. So the idea
is, a server side call begins, it gets spun off on another thread to keep
the UI painting - but, the code flow cannot return to the caller until
the server side call completes, because the caller expects the data.

The only way I could find to do this, was to open a modal dialog after
spinning off the new thread to do the server call. Then the callback
would close the dialog, causing the UI thread to once again begin
processing. The callback had also set the return data, so everything
worked fine.

The only problem was that every time the dialog popped open (which had
an animated image to let the user know work was happening), it would
activate, then it would close and the main form would reactivate. One
logical operation sometimes involved several server side calls - and
each would pop open the dialog and then close, resulting in a lot of
flashing as the main form deactivated then reactivated.

The dialog was the only way I could find to block the main thread, and
yet keep the UI painting, and at the same time prevent the user from
clicking anywhere back on the original form and trying to do something
while in the midst of an operation (because the dialog was modal).

Any suggestions for how to implement this kind of thing? Telling the
thread to sleep or anything of that nature does not keep the UI
painting - and I'm thinking Applicaiton.DoEvents is going to allow the
user to click anywhere and mess with things, which isn't going to work
either.


Mar 19 '08 #4
This is a generic server side calling piece. Thousands of call streams go
through it - in all diff combinations.

So a click handler might have:

run some code dealing with UI object
server call
run some code dealing with UI objects
server call
run some code dealing with UI objects

So, if the dialog is opened up front, and then the click handler as a whole
is run on a separate thread, then anything touching UI objects is going to
die because UI things have to run on the UI thread.

Otherwise, it is just the server calls that are run on a separate thread -
which then brings up the point of how to block while waiting for the async
server call and yet paint the UI.

Yes, I realize multiple server side calls may not be optimal - but sometimes
they are necessary, and it is just not predictable how code was written and
it can't all be redone.
"Rich" <no****@nowhere.comwrote in message
news:uo**************@TK2MSFTNGP05.phx.gbl...
Can't you keep the dialogue open until all the transactions have
completed?

Instead of creating a dialogue each time you kick off a thread, open a
dialogue which then handles all the transactions in one go?

--

Rich

http://www.badangling.com
...talking pollocks since 1996

"Marina Levit" <so*****@someplace.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>The entire application would have to be disabled as really any user
interaction could invalidate things. If the task happened to be short, it
would also look like a different type of flashing to disable/enable it. I
am fairly certain that those in charge of the look of the app are not
going to go for that, though that is an option.
"Patrice" <http://www.chez.com/scribe/wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>Generally you launch a background thread that does the work so that the
UI thread is kept responsive. You disable the approprirate controls so
that the user can't do something that would cause problem '(o r you can
test if a background taks is running)...

--
Patrice

"Marina Levit" <so*****@someplace.coma écrit dans le message de news:
uv****************@TK2MSFTNGP06.phx.gbl...
I am trying to do some processing on a background thread while keeping
the UI painting. However, this is a generic server side call routine -
and it needs to block until the server side call completes. So the idea
is, a server side call begins, it gets spun off on another thread to
keep the UI painting - but, the code flow cannot return to the caller
until the server side call completes, because the caller expects the
data.

The only way I could find to do this, was to open a modal dialog after
spinning off the new thread to do the server call. Then the callback
would close the dialog, causing the UI thread to once again begin
processing. The callback had also set the return data, so everything
worked fine.

The only problem was that every time the dialog popped open (which had
an animated image to let the user know work was happening), it would
activate, then it would close and the main form would reactivate. One
logical operation sometimes involved several server side calls - and
each would pop open the dialog and then close, resulting in a lot of
flashing as the main form deactivated then reactivated.

The dialog was the only way I could find to block the main thread, and
yet keep the UI painting, and at the same time prevent the user from
clicking anywhere back on the original form and trying to do something
while in the midst of an operation (because the dialog was modal).

Any suggestions for how to implement this kind of thing? Telling the
thread to sleep or anything of that nature does not keep the UI
painting - and I'm thinking Applicaiton.DoEvents is going to allow the
user to click anywhere and mess with things, which isn't going to work
either.


Mar 19 '08 #5

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

Similar topics

1
by: patty | last post by:
I have created a simple C# application which instantiates an object of a class I defined and calls a single method on the class. When I run the application in the debugger, I see there are 3...
8
by: Ron Holmes | last post by:
I want to place a background image on a windows form. Is there a way to prevent the image from Tiling without using an image box resized to the size of the form? I am using Visual Studio 2003...
0
by: Gomaw Beoyr | last post by:
Hello The book "C# Black Book" chapter about Threads says that a "background thread" cannot communicate directly with a visual element, e.g. a label, and thus has to use the BeginInvoke method,...
2
by: Robert Misiak | last post by:
Hi everyone- I've done a lot of searching around on the web and I'm sure the answer to this question is no, but I'll ask anyway. Is it possible to create an inherited MonthCalendar control and...
13
by: orekin | last post by:
Hi There I have been programming C# for a couple of months and am trying to master Threading. I understand that ThreadPool uses background threads (see code example in MSDN page titled...
12
by: Odalrick | last post by:
I need to draw visible lines on pictures with wxPython. That means I can't simply use, for instance, a black line since it wont be visible on a black or dark picture. Painting applications like...
33
by: bonk | last post by:
I have an application that needs to perform some background work, i.e. Logging, wich must not block the main thread. How would I basically design such a scenario? It is obvious that I should do...
7
by: csharpula csharp | last post by:
Hello, I got a question regarding the usage of background worker. How can I run few threads via background worker with different objects as parameter each time. I understood that I can't do...
19
by: david.karr | last post by:
If in my CSS I set the "background-color" property on the "body" element, it only covers the background of the elements defined in the body, up to the current width and height of the page. However,...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: 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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.