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

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 2226
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, "Programming .NET Components", there
is a section on events and multithreading, along with a utility class
(EventsHelper) which will take an implementation of ISynchronizeInvoke and
perform the event firing on the appropriate thread.

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

"Tomaz Koritnik" <no****@nospam.com> wrote in message
news:ja********************@news.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**********@nospam.avnet.com> wrote in message
news:%2****************@TK2MSFTNGP09.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.com> wrote in
message news:%2****************@TK2MSFTNGP15.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, "Programming .NET Components",
there is a section on events and multithreading, along with a utility
class (EventsHelper) which will take an implementation of
ISynchronizeInvoke and perform the event firing on the appropriate thread.

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

"Tomaz Koritnik" <no****@nospam.com> wrote in message
news:ja********************@news.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.com

"Tomaz Koritnik" <no****@nospam.com> wrote in message
news:gU********************@news.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.com> wrote
in message news:%2****************@TK2MSFTNGP15.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, "Programming .NET Components",
there is a section on events and multithreading, along with a utility
class (EventsHelper) which will take an implementation of
ISynchronizeInvoke and perform the event firing on the appropriate
thread.

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

"Tomaz Koritnik" <no****@nospam.com> wrote in message
news:ja********************@news.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
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...
5
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...
1
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...
8
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...
5
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...
1
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...
4
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...
1
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...
10
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.