473,796 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread Logic Question

All,

I have a UI form calling a class object that contains a timer that
routinely draws intensive information to the screen (~30 fps). The
drawing is invoked on the main UI thread. I need the user to be able
to interact with the UI while the drawing is happening (dynamically
change drawing properties). Since the drawing is happening on the main
UI thread, the UI form doesn't receive the user control events
consistently (if at all).

Does anyone have some suggestions on how to model this scenario so that
I can receive events on the UI form but continue to draw? How would I
tackle this in C#? Thanks.

Sep 26 '06
13 1604
Hi Jordan,

Unless you're using the System.Windows. Forms.Timer or explicitly marshaling the timer calls to the UI thread, your drawing code is
probably executing on a thread other than the UI thread.

I only mention this because you never said which type of Timer you're using and you seemed to imply that breaking up the drawing
function into multiple methods has helped, which leads me to believe that you're executing that code on a different thread to begin
with. This is contrary to your statement, "the architecture of our system forces all drawing to be invoked on the UI thread".

HTH

--
Dave Sexton

"Jordan" <jo***********@ gmail.comwrote in message news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
All,

I have a UI form calling a class object that contains a timer that
routinely draws intensive information to the screen (~30 fps). The
drawing is invoked on the main UI thread. I need the user to be able
to interact with the UI while the drawing is happening (dynamically
change drawing properties). Since the drawing is happening on the main
UI thread, the UI form doesn't receive the user control events
consistently (if at all).

Does anyone have some suggestions on how to model this scenario so that
I can receive events on the UI form but continue to draw? How would I
tackle this in C#? Thanks.

Sep 26 '06 #11
Dave,

No, it is drawing in the main UI thread. Here is what happens:

1) Class uses server timer (System.Timers. Timer)
2) Timer elapsed - call to RedrawViewers
3) Internally, RedrawViewers invokes to the main UI thread
4) Main UI thread handles OnAfterDraw event and paints to screen

What I did was make the painting more efficient and lower the FPS timer
rate (if I jump to 60 fps, it gets messy again).

Dave Sexton wrote:
Hi Jordan,

Unless you're using the System.Windows. Forms.Timer or explicitly marshaling the timer calls to the UI thread, your drawing code is
probably executing on a thread other than the UI thread.

I only mention this because you never said which type of Timer you're using and you seemed to imply that breaking up the drawing
function into multiple methods has helped, which leads me to believe that you're executing that code on a different thread to begin
with. This is contrary to your statement, "the architecture of our system forces all drawing to be invoked on the UI thread".

HTH

--
Dave Sexton

"Jordan" <jo***********@ gmail.comwrote in message news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
All,

I have a UI form calling a class object that contains a timer that
routinely draws intensive information to the screen (~30 fps). The
drawing is invoked on the main UI thread. I need the user to be able
to interact with the UI while the drawing is happening (dynamically
change drawing properties). Since the drawing is happening on the main
UI thread, the UI form doesn't receive the user control events
consistently (if at all).

Does anyone have some suggestions on how to model this scenario so that
I can receive events on the UI form but continue to draw? How would I
tackle this in C#? Thanks.
Sep 26 '06 #12
Hi Jordan,

Sorry I doubted you!

It all sounds good to me.

--
Dave Sexton

"Jordan" <jo***********@ gmail.comwrote in message news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
Dave,

No, it is drawing in the main UI thread. Here is what happens:

1) Class uses server timer (System.Timers. Timer)
2) Timer elapsed - call to RedrawViewers
3) Internally, RedrawViewers invokes to the main UI thread
4) Main UI thread handles OnAfterDraw event and paints to screen

What I did was make the painting more efficient and lower the FPS timer
rate (if I jump to 60 fps, it gets messy again).

Dave Sexton wrote:
>Hi Jordan,

Unless you're using the System.Windows. Forms.Timer or explicitly marshaling the timer calls to the UI thread, your drawing code
is
probably executing on a thread other than the UI thread.

I only mention this because you never said which type of Timer you're using and you seemed to imply that breaking up the drawing
function into multiple methods has helped, which leads me to believe that you're executing that code on a different thread to
begin
with. This is contrary to your statement, "the architecture of our system forces all drawing to be invoked on the UI thread".

HTH

--
Dave Sexton

"Jordan" <jo***********@ gmail.comwrote in message news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
All,

I have a UI form calling a class object that contains a timer that
routinely draws intensive information to the screen (~30 fps). The
drawing is invoked on the main UI thread. I need the user to be able
to interact with the UI while the drawing is happening (dynamically
change drawing properties). Since the drawing is happening on the main
UI thread, the UI form doesn't receive the user control events
consistently (if at all).

Does anyone have some suggestions on how to model this scenario so that
I can receive events on the UI form but continue to draw? How would I
tackle this in C#? Thanks.

Sep 26 '06 #13
No problems - thanks for the help.

Dave Sexton wrote:
Hi Jordan,

Sorry I doubted you!

It all sounds good to me.

--
Dave Sexton

"Jordan" <jo***********@ gmail.comwrote in message news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
Dave,

No, it is drawing in the main UI thread. Here is what happens:

1) Class uses server timer (System.Timers. Timer)
2) Timer elapsed - call to RedrawViewers
3) Internally, RedrawViewers invokes to the main UI thread
4) Main UI thread handles OnAfterDraw event and paints to screen

What I did was make the painting more efficient and lower the FPS timer
rate (if I jump to 60 fps, it gets messy again).

Dave Sexton wrote:
Hi Jordan,

Unless you're using the System.Windows. Forms.Timer or explicitly marshaling the timer calls to the UI thread, your drawing code
is
probably executing on a thread other than the UI thread.

I only mention this because you never said which type of Timer you're using and you seemed to imply that breaking up the drawing
function into multiple methods has helped, which leads me to believe that you're executing that code on a different thread to
begin
with. This is contrary to your statement, "the architecture of our system forces all drawing to be invoked on the UI thread".

HTH

--
Dave Sexton

"Jordan" <jo***********@ gmail.comwrote in message news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
All,

I have a UI form calling a class object that contains a timer that
routinely draws intensive information to the screen (~30 fps). The
drawing is invoked on the main UI thread. I need the user to be able
to interact with the UI while the drawing is happening (dynamically
change drawing properties). Since the drawing is happening on the main
UI thread, the UI form doesn't receive the user control events
consistently (if at all).

Does anyone have some suggestions on how to model this scenario so that
I can receive events on the UI form but continue to draw? How would I
tackle this in C#? Thanks.
Sep 26 '06 #14

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

Similar topics

31
2512
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not tipical) from the Internet and doing some processing on those would be considered to be a big/long task for a thread from a pool. In our app it is possible to break the task into some small ones (thread per fetch and processing thereafter or event...
8
3183
by: Maurice LING | last post by:
Hi, I just have a simple question about threads. My classes inherits from threading.Thread class. I am calling threading.Thread.run() method to spawn a few threads to parallel some parts of my program. No thread re-use, pooling, joining ... just plainly spawn a thread, run a routine. So, at the end of run(), what happens to the thread? Just die? While I am on it, can threading.Thread.run() accept any parameters?
4
1624
by: Simo | last post by:
hello, can anyone please tell me if the following structure is thread safe visit.cs class Visit : System.Web.UI.Page { //Variables IVisitProtocol m_oVisitProtocol public void Configure(IVisiteProtocol oVisiteProtocol) { this.m_oVisitProtocol = oVisitProtocol;
5
14134
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in my FileIO class) I've established Public Event in my core logic classes along with RaiseEvents (that will updated a progress bar on the UI side). This all works great when I'm NOT using Threading (BackgroundWorker), however, as soon as I...
27
1741
by: Ritesh Raj Sarraf | last post by:
Hi, I have some basic doubts about thread. I have a list which has items in it which need to be downloaded from the internet. Let's say list is: list_items which has 100 items in it.
2
1949
by: tshad | last post by:
I have a Service that starts a thread that never ends. When I stop the service from the Service Applet, does it kill the thread or do I need to do it myself? If it isn't killed, what happens when I start the service again. ************************************************** Protected Overrides Sub OnStart(ByVal args() As String) Dim theThread As Thread
5
3028
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...
5
6028
by: salberts | last post by:
Hi, I am writing an application that has its UI and Logic layers. My initial idea was to launch the two layers on two different threads and manage calls made by the UI to the Logic manually. Which means handling the Sleep/Wakeup of the logic thread all by myself. This looks reasonable to me in the way that the UI and the Logic run separately and only send messages to each other. The main disadvantage of thos method is that I have to...
11
3801
by: Jon Slaughter | last post by:
Is there any way to start a terminated thread without using a pool or creating a new thread object? void counter() { clicks = 0; clock.Start(); while (counterActive) { clicks++;
0
9683
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
9529
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10231
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
10013
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
9054
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
4119
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
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
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.