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 10, 2018 in Others by Bharani
• 4,660 points
1,070 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 10, 2018 by nirvana
• 3,130 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 7, 2019 in Others by Frankie
• 9,830 points
4,688 views
0 votes
0 answers

How to create a batch file in windows?

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

Jul 4, 2019 in Others by sindhu
711 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,460 points
1,796 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,460 points
1,138 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,260 points
6,758 views
0 votes
1 answer

How interactive graphs are generated in Tableau?

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

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

SQLite.Net not being able to create text file in Win IoT Library!

That exception comes when access limited to ...READ MORE

answered Aug 3, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,028 views
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,130 points
1,520 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP