Events Threading in Windows Forms

0 votes

I have a form receiving asynchronous callbacks from an object on random worker threads. I pass data to my main thread using delegates like in the snippet below and I use it to update onscreen controls. But, the performance is so bad that upon reaching 500 updates per second, my entire program gets locked up. And, I'm sure that it's not my GUI processing causing this problem because I can simulate a similar level of update within my form without any problems at all. Do I need to be using a better process for handing off data from one thread to another?

delegate void DStatus( MyStatus obj );
DStatus _status; // set to MainThreadOnStatus during construction

// this function only called on form's owner thread
void MainThreadOnStatus( MyStatus obj )
{
   // screen updates here as needed
}

// this function called by arbitrary worker threads in external facility
void OnStatus( MyStatus obj )
{
   this.BeginInvoke( _status, obj );
}
Nov 9, 2018 in Others by Bharani
• 4,620 points
198 views

1 answer to this question.

0 votes
I don't think you should be updating your UI at every event, like at least not so often as x times per second. Rather, utilize a StopWatch or some other timing system that collects events for an interval of time, and update your UI just when needed. And, in cases where all events have to be captured, you could just collect all of them in a Queue and keep firing events just as often. And, ensure that the Queue is processed by the event handler to update UI at once for all events that are queued.
answered Nov 9, 2018 by nirvana
• 3,150 points

Related Questions In Others

0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 6, 2019 in Others by Frankie
• 9,810 points
285 views
0 votes
0 answers

How to create a batch file in windows?

What is a batch file and How ...READ MORE

Jul 3, 2019 in Others by sindhu
162 views
0 votes
1 answer

How to install Flutter in Windows system?

Hi@akhtar, You can follow the below-given steps to ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,220 points
453 views
0 votes
1 answer

How to install Dart in Windows system?

Hi@akhtar, Dart is the programming language used to code Flutter apps. ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,220 points
235 views
0 votes
1 answer

How to run two commands in one line in Windows CMD?

Hi@MD, You can use the Logical And operator ...READ MORE

answered Oct 5, 2020 in Others by akhtar
• 38,180 points
1,660 views
0 votes
1 answer

How interactive graphs are generated in Tableau?

Lot of back end code is shared ...READ MORE

answered Apr 13, 2018 in Tableau by xyz
• 1,560 points
162 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Avoiding memory leaks in C++

If you use smart pointers at all ...READ MORE

answered Nov 5, 2018 in Others by nirvana
• 3,150 points
687 views