473,834 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(f loat Percentage);

public void SetProgress(flo at Percentage)

{

if (InvokeRequired )

{

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

return;

}

ultraProgressBa r1.Value = (int)Percentage ;

Invalidate(true );

Update();

//Application.DoE vents();

}
Nov 16 '05 #1
5 2197
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****@blahhhh h.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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(f loat Percentage);

public void SetProgress(flo at Percentage)

{

if (InvokeRequired )

{

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

return;

}

ultraProgressBa r1.Value = (int)Percentage ;

Invalidate(true );

Update();

//Application.DoE vents();

}

Nov 16 '05 #2
Hi Willy

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:u2******** ******@TK2MSFTN GP10.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 serialconnectio n 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****@blahhhh h.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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(f loat 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****@blahhhh h.com> wrote in message
news:eK******** ******@TK2MSFTN GP09.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
4921
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 GUI is updating.  I've done that before without a problem, however, now, I need to pass variables to the separate Thread or Runnable that I'm using.  I'm using something like this: //Other code setting things up and updating GUI //Variables...
8
7600
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 looping function the window becomes unmovable and cannot close under its own direction (the upper right "close 'X'") My first attempt to solve the problem was to have the looping function execute as its own thread, the idea being this would...
8
3326
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 window is not responding to the user. The user is now able to minimize, move the window because the code is too busy on it's own work. (and they are all running on the same thread)
3
10060
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 extern IntPtr WindowFromPoint(System.Drawing.Point Point); //... h = (System.Drawing.Point)hits; // this is an array of Point objects ip = WindowFromPoint(h);
2
6437
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 Thread(new ThreadStart(runAnalysis)); analysisThread.Start();
20
3039
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 delegate inside the UI that I call to update the progress meter. I use the Suspend() and Abort() methods based on button events. I can watch the progress meter increase just fine when the thread is running. When I select Start, I enable the Cancel...
5
2014
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 have is that if I try to move (drag) the form's window around the screen, or to scroll the ListView control, the loop pauses until I stop dragging or scrolling. I want the loop to continue whilst I'm doing trivial things like moving the window...
5
12535
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 update the datasource - awesome, but I have an issue with updating from a different thread. Here is my datasource, a person class that raises the PropertyChanged event: class Person : INotifyPropertyChanged {
5
3029
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 realize it's not wise, and in some circumstances, not even possible to update the controls from the stream other than the main stream. I believe there are two recommended ways to handle this situation. 1. Use Invoke() to "call" an updater method...
0
9799
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
10510
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10548
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
10219
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...
0
9331
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7758
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
6954
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
5627
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...
1
4427
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.