473,405 Members | 2,354 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,405 software developers and data experts.

Window drawn from thread not updating

My progress window is created by a secondary thread and then updated by it
while a file is uploaded. There's an avi animation control on there that
should show the move file avi. Plus a progress bar.
Im having problems as the screen isn't being redrawn properly. If I call
DoEvents each time then it works ok.
I want to dump DoEvents to prevent problems.
I'm calling the following from the progress property set function.
InvokeRequired always fails (as the thread that created the window is also
trying to update the percentage)
delegate void FloatDelegate(float Percentage);

public void SetProgress(float Percentage)

{

if (InvokeRequired)

{

BeginInvoke(new FloatDelegate(SetProgress), new object[]{Percentage});

return;

}

ultraProgressBar1.Value = (int)Percentage;

Invalidate(true);

Update();

//Application.DoEvents();

}
Nov 16 '05 #1
5 2178
Some questions....
I'm I right to suppose you created a windows form from the non UI thread? If
so, did you start a message pump by calling Application.Run(...); passing a
reference to your progress window form?
Also I guess that your "avi animation control" is an active-X control and as
such need to run on an STA thread, did you initialize the secondary thread
as STA?
And last but not least, why do you need to run this on a secondary thread?
You should definitely try to handle all your UI interaction on a single UI
thread.
Willy.

"Claire" <bl****@blahhhhh.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
My progress window is created by a secondary thread and then updated by it
while a file is uploaded. There's an avi animation control on there that
should show the move file avi. Plus a progress bar.
Im having problems as the screen isn't being redrawn properly. If I call
DoEvents each time then it works ok.
I want to dump DoEvents to prevent problems.
I'm calling the following from the progress property set function.
InvokeRequired always fails (as the thread that created the window is also
trying to update the percentage)
delegate void FloatDelegate(float Percentage);

public void SetProgress(float Percentage)

{

if (InvokeRequired)

{

BeginInvoke(new FloatDelegate(SetProgress), new object[]{Percentage});

return;

}

ultraProgressBar1.Value = (int)Percentage;

Invalidate(true);

Update();

//Application.DoEvents();

}

Nov 16 '05 #2
Hi Willy

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
Some questions....
I'm I right to suppose you created a windows form from the non UI thread? If so, did you start a message pump by calling Application.Run(...); passing a reference to your progress window form?
It's a standard windows forms application, the application main form is a
config form for the serial port and it hides itself in the system tray on
startup.

We're using Sax Communications .net controls. The thread is created
internally by their serialconnection component.
The dataavailable event is thrown and it's run in the context of their
thread. I don't know anything further, but the thread ID seems to remain the
same over the application lifetime. There's no technical information in
their help files.
Also I guess that your "avi animation control" is an active-X control and as such need to run on an STA thread, did you initialize the secondary thread
as STA? The Avi animation control is part of the Infragistic series of .net
components. It works ok when I DoEvents but not from the thread.
And last but not least, why do you need to run this on a secondary thread?
You should definitely try to handle all your UI interaction on a single UI
thread.

See above. The client drives the communication protocol and my app just
listens, provides services to the client and sits in the system tray (so
this worker thread is in reality the main/busiest thread). The comms
protocol opens the progress form just before a file transfer starts and
closes it when it ends.

Nov 16 '05 #3
Hi Claire,

"Claire" <bl****@blahhhhh.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
My progress window is created by a secondary thread and then updated by it
while a file is uploaded. There's an avi animation control on there that
should show the move file avi. Plus a progress bar.
Im having problems as the screen isn't being redrawn properly. If I call
DoEvents each time then it works ok.
I want to dump DoEvents to prevent problems.
I'm calling the following from the progress property set function.
InvokeRequired always fails (as the thread that created the window is also
trying to update the percentage)
delegate void FloatDelegate(float Percentage);

<snip>

Is the secondary thread on which the progress window created also the
thread that does the file upload? Typically, long-running processes (like
file uploads) are done on a separate thread from the user interface in order
that the user interface will continue to update and continue to be
responsive.

In your case, the secondary thread is busy uploading the file and
therefore isn't processing the window messages that are telling the progress
window to update itself. The DoEvents method causes the current thread to
explicitly go process the window messages in the queue and then return,
which is why calling it causes the progress window to update.

The best thing you can do, IMO, is to create and update the progress
form on the main user interface thread, and do the file upload on a separate
background thread.

Regards,
Daniel
Nov 16 '05 #4
Thanks for answering Daniel
That's what Id like/trying to do. Pre .net I'd post a message to the main
form and the main application process would pick it up.
If I use Invoke as was suggested, then the same thread that produced the
dialog would call the progress bar update. So the problem remains.
I can't see how to break out of the thread context and into the main process
in order to create or callback to the progress form.
Nov 16 '05 #5
Hi Claire,

"Claire" <bl****@blahhhhh.com> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl...
Thanks for answering Daniel
That's what Id like/trying to do. Pre .net I'd post a message to the main
form and the main application process would pick it up.
If I use Invoke as was suggested, then the same thread that produced the
dialog would call the progress bar update. So the problem remains.
I can't see how to break out of the thread context and into the main process in order to create or callback to the progress form.


How/where is the progress window being created?

Regards,
Daniel
Nov 16 '05 #6

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

Similar topics

2
by: Hal Vaughan | last post by:
First, I am aware of both SwingUtilities.invokeLater(), and of using Thread to create a new thread.  These are part of the problem. I want to have something running in the background, while the...
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
8
by: Serge | last post by:
Hi, I have some intensive code that is running on my main thread. I try to show a status update on a 'status form'. The problem that i have is that because it is running in the same thread the...
3
by: Logan McKinley | last post by:
I need to draw a dot where ever the user clicks (which will be on either the form or a couple dynamically placed picture boxes). I thought the following code should work: //--- static public...
2
by: bob | last post by:
Hello, In my appliction I try to pop up a progress dialog box while an analysis is being run: //method progress window public void Run(IWin32Window parent) { Thread analysisThread = new...
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
5
by: Wicksy | last post by:
Hi all. I have a VB.NET app with a loop running that is continually managing a number of threads AND updating a ListView object depending on the results of the worker threads. The problem I...
5
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I...
5
by: temp2 | last post by:
Hello, I have an app that reads data params from a stream and updates controls accordingly. The stream reader is on a different thread than the main thread that created the controls. I fully...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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,...
0
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,...
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
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...
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...

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.