473,809 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reporting progress from worker thread

I have a worker thread doing some long calculation and I'd like to report
progress (percent done,...). One easy way it to call Control.Invoke( ). But
is there another way of doing this without using controls that are
associated with window handles?

regards
Tomaz
Nov 17 '05 #1
5 2250
Tomaz Koritnik wrote:
I have a worker thread doing some long calculation and I'd like to
report progress (percent done,...). One easy way it to call
Control.Invoke( ). But is there another way of doing this without
using controls that are associated with window handles?

regards
Tomaz


There are a variety of ways. One simple way could be to update stats in an
object that both threads have access to whenever it's convienient for the
worker thread to do so. The foreground thread could then display results
(by reading stats from that object) to the user on a timed basis (update the
UI once every N seconds, etc.). You'd want to control access to
updating/reading that object of course.

--
Gordon Smith (eMVP)
-- Avnet Applied Computing Solutions
Nov 17 '05 #2
Tomaz,

If you want to have some sort of notification that is visual, then
ultimately, at some level, you will have to call the Invoke method to make
the call to update the UI.

You can have your component fire events to indicate progress, however,
the handlers will have to eventually call Invoke because the event being
fired is not on the UI.

If you check out Juval Lowy's book, "Programmin g .NET Components", there
is a section on events and multithreading, along with a utility class
(EventsHelper) which will take an implementation of ISynchronizeInv oke and
perform the event firing on the appropriate thread.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Tomaz Koritnik" <no****@nospam. com> wrote in message
news:ja******** ************@ne ws.siol.net...
I have a worker thread doing some long calculation and I'd like to report
progress (percent done,...). One easy way it to call Control.Invoke( ). But
is there another way of doing this without using controls that are
associated with window handles?

regards
Tomaz

Nov 17 '05 #3
Hi

This pull-model is just what I thought about too and it's a great idea. Stat
object would use critical section to support multithreading and main thread
would get data from info object using a timer with speed of 1Hz.

regards
Tomaz

"Gordon Smith (eMVP)" <Go**********@n ospam.avnet.com > wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Tomaz Koritnik wrote:
I have a worker thread doing some long calculation and I'd like to
report progress (percent done,...). One easy way it to call
Control.Invoke( ). But is there another way of doing this without
using controls that are associated with window handles?

regards
Tomaz


There are a variety of ways. One simple way could be to update stats in
an object that both threads have access to whenever it's convienient for
the worker thread to do so. The foreground thread could then display
results (by reading stats from that object) to the user on a timed basis
(update the UI once every N seconds, etc.). You'd want to control access
to updating/reading that object of course.

--
Gordon Smith (eMVP)
-- Avnet Applied Computing Solutions

Nov 17 '05 #4
Hi

Thanks for answering. Is there a simple way to use messages (like in Win32)
for communication? I will also check the Juval Lowy's book because I found
it very interesting.

regards
Tomaz
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Tomaz,

If you want to have some sort of notification that is visual, then
ultimately, at some level, you will have to call the Invoke method to make
the call to update the UI.

You can have your component fire events to indicate progress, however,
the handlers will have to eventually call Invoke because the event being
fired is not on the UI.

If you check out Juval Lowy's book, "Programmin g .NET Components",
there is a section on events and multithreading, along with a utility
class (EventsHelper) which will take an implementation of
ISynchronizeInv oke and perform the event firing on the appropriate thread.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Tomaz Koritnik" <no****@nospam. com> wrote in message
news:ja******** ************@ne ws.siol.net...
I have a worker thread doing some long calculation and I'd like to report
progress (percent done,...). One easy way it to call Control.Invoke( ). But
is there another way of doing this without using controls that are
associated with window handles?

regards
Tomaz


Nov 17 '05 #5
Tomaz,

Why would you want to use messages? It's much easier to just declare a
delegate type and then attach the method you want to call to it, and pass it
(with any parameters) to the Invoke method.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Tomaz Koritnik" <no****@nospam. com> wrote in message
news:gU******** ************@ne ws.siol.net...
Hi

Thanks for answering. Is there a simple way to use messages (like in
Win32) for communication? I will also check the Juval Lowy's book because
I found it very interesting.

regards
Tomaz
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote
in message news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Tomaz,

If you want to have some sort of notification that is visual, then
ultimately, at some level, you will have to call the Invoke method to
make the call to update the UI.

You can have your component fire events to indicate progress, however,
the handlers will have to eventually call Invoke because the event being
fired is not on the UI.

If you check out Juval Lowy's book, "Programmin g .NET Components",
there is a section on events and multithreading, along with a utility
class (EventsHelper) which will take an implementation of
ISynchronizeInv oke and perform the event firing on the appropriate
thread.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Tomaz Koritnik" <no****@nospam. com> wrote in message
news:ja******** ************@ne ws.siol.net...
I have a worker thread doing some long calculation and I'd like to report
progress (percent done,...). One easy way it to call Control.Invoke( ).
But is there another way of doing this without using controls that are
associated with window handles?

regards
Tomaz



Nov 17 '05 #6

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

Similar topics

4
11622
by: Alexander | last post by:
Hi, I have written a program that takes on some operations much more time than I expected. As I have seen users clicking wildly on the screen to make something happen, I want to follow the microsoft principles: always show them something ;) First I made up a little status dialog containing a gif image to show a little animation and a TextBox for a changing status message during the work of the main program. Just showing the dialog box...
5
7385
by: Søren Reinke | last post by:
Hi there I am working on a program where the user should be able to import some CSV files. With my set of test data, it takes about 2 minutes to import, while it is importing the program sort of freezes. Therefore i would like to open a little window with a progress bar in it that shows how far the import has come.
1
5205
by: David Veeneman | last post by:
What's the best way to gracefully exit an app while an asynchronous operation is in progress? Let's say I have spawned a worker thread using the BackgroundWorker component. If I exit the application while the worker thread is running, the app crashes. It doesn't do any good to call CancelAsync() on the worker thread from a FormClosing event handler--Since the worker thread is running asynchronously, the main thread will continue the...
8
4761
by: WhiteWizard | last post by:
I guess it's my turn to ASK a question ;) Briefly my problem: I am developing a Windows app that has several User Controls. On one of these controls, I am copying/processing some rather large binary files, so have created a second thread to do the processing. This thread is set to be the LOWEST priority. So far so good with all that. HOWEVER, I am trying to provide some feedback to the user (the bane of our existence!) via a progress...
5
10912
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I have a form that has a button. ( this form is a child form of a parent form ( main form ). Anway...in this child form I have a button, and if clicked a bunch of code will get executed. I would like to show a Progress Bar / form in modal/ShowDialog...
1
3236
by: Bob | last post by:
Hi, I am having trouble seeing how this bolts together. The UI starts a process which involves a long running database update. All Database activity is handled by a class called DT. DT has a progress event. So I added a bw to the form. The Dowork Calls a method which instantiates a DT and calls its Dataprocessing method.
4
2057
by: dgleeson3 | last post by:
Hello all Yes I know its been done before, but something silly is killing me on this. I have the standard progress bar and worker thread scenario with progress of the worker thread being fed back to the main UI and displayed on the progress bar. I have a delegate and am using BeginInvoke. But the progress bar is not updating.
1
1689
by: spinoza1111 | last post by:
I want the GUI of the spinoza system to not piss me off with the usual type of progress reporting one sees: the flashy, colorful, and utterly uninformative gizmos that go back and forth and round and round until who knows when. Therefore, the following C Sharp .Net code constitutes a theory of progress reporting. I claim that any fixed-count (limit available at run time before the start) for loop can be monitored by considering it as...
10
2054
by: =?Utf-8?B?YXVsZGg=?= | last post by:
am having a hard time wrapping my head around "backgroundworker" class and updates to the window form that calls it. i have some questions about how to update windows form controls. i have multiple labels and i'm using a text box for status updates. the labels change when a task completes. the text box report what task is running. so 1) when i call _ProgressChange i need that function to passed the label i
0
9721
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
10376
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...
0
10115
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
9199
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
7660
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
6881
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
5550
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...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.