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,550 points
69 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,060 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 in Others by Frankie
• 9,810 points
33 views
0 votes
0 answers

How to create a batch file in windows?

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

Jul 3 in Others by sindhu
28 views
0 votes
0 answers

why linux is more secure than windows?

which features make linux more secure than ...READ MORE

Jul 11, 2018 in Others by kristena1234
• 160 points
39 views
0 votes
1 answer

Reducing sequences in an array of strings

I've written a C# app to solves ...READ MORE

answered Nov 2, 2018 in Others by DataKing99
• 8,130 points
53 views
0 votes
1 answer

Using/Handling colon inside a JSF generated HTML element ID in CSS selector

Yes, you can.  Just Backslash (\) the colon.  Like ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,130 points
348 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,550 points
48 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,060 points
104 views