I'm trying to update a property on an arraylist of visual components on a form, getting the property value to set by calling a method on another object. However, performance is unacceptably slow.
publicdelegatevoid VisualComponentUpdateHandler(VisualComponent v, int val);<br />
publicvoid VisualComponentUpdate(VisualComponent v, int val)<br />
v.Value = val;<br />
and running in a seperate thread:
VisualComponentUpdateHandler d = new VisualComponentUpdateHandler(VisualComponentUpdate);<br />
int val;<br />
while (true)<br />
foreach (VisualComponent v in visualComponentArrayList)<br />
val = sourceObject.GetValue(Convert.ToInt32(v.Name));<br />
d.Invoke(v, val)<br />
I added the Thread.Sleep(100) because without it, the visuals don't seem to update.
I've got anything up to 128 of the visual components to update - they're custom components derived from ProgressBar, displaying a measurement which is obtained from a program running on a seperate machine which passes a new sourceObject every 250ms to the program via .NET remoting (this updating mechanism runs in another thread and doesn't seem to be affected by the slowdown in response which occurs when the property update thread is running).
Might be a stupid questions, but.. Why are you doing d.Invoke(v, val) ? Shouldn't it be v.Invoke(d, new object... or something like that? You are attempting to marshall back to the gui thread to update your control right? I think Delegate.Invoke would spawn yet another thread , where it may not be safe to update GUI Controls (which might explain why you need a sleep to make it work)
Yes, sorry - I made a typo. It does work; it's just that it renders the GUI too unresponsive. I'm looking for smooth-ish updating on all of the controls and looping through them (even with Thread.Sleep in there) seems to result in massive CPU load and sluggish display. Perhaps it is something to do with the way in which the thread which performs the invoke calls back to the GUI thread obtains the values to set the component properties to (it's not too bad if I just generate some numbers within the updating thread and use those instead).
Right, got it. Suspicion confirmed. The object I was calling the method on in order to get the values was being blocked by another thread accessing it. Stick the invokes to update the component properties into the same thread and the problem's gone away. Thanks ;P
Hello fellows. I need your help. I have a Windows.Forms application which makes a connection to a database about 5 - 10 seconds. While I'm trying to connect to the database, an animated control starts an animation . After the connection is made I stop the animation and want to run another function to fill a DataGrid control.
private void OpenConFunction()
//... some code
private void AfterConnFunction()
//... some code to fill DataGrid control
private void myButton_Click(object sender, System.EventArgs e)
Thread t = new Thread(new ThreadStart(OpenConFunction));
this.AnimatedControl.Start(); //Suppose AnimatedControl
//has two methods one to start animation and a second one to stop it
What has to be the code after OpenConFunction returns? I want to invoke the AfterConnFunction and stop the AnimatedControl animation?
call the animation method asynchronously , inside which u have following code
//bnFinished flag is class level var and will be set to true when db
//end the async method call..
Thanks for the reply. Unfortunately, your suggestion didn't help me. I think I need to call the OpenConFunction() in a separate thread. But I don't know how to start the AfterConnFunction when OpenConFunction ends.
It's incredible how many people don't even bother with the simplest of things when posting a question.
First thing they should always do is google for an answer.
The second (rule of fight club) thing is they should google again for the answer, and again and again with different keywords until they are sure theres nothing obvious about. Twenty minutes research should not be an unreasonable burden upon someone who is seeking free help.
There there is the problem of txtspk, if you have a limitation of 160 characters because your using SM its ndrstndbl tat u mgt nt use whle wrds. But when typing online you don't have that limitation, the more expressive the language you use the more information you can convey to those your asking for help.
Theres the problem of not providing enough information. Sometimes someone will give you they're interpretation of the error message, which is almost useless for searching with. Another twist is sometimes (and most developers are bad for this) someone will ask about what they think the solution is rather than describing the problem. This means you can spend ages helping with something which actually has nothing to do with the actual issue.
Some people think that it is their right to receive help and demand that you give an answer or give an in depth essay rather than a link to google. They can seem to grasp the fact that you're helping off your own back, your not getting paid to think for them.
How can I determine "day size" of a specific month using a MonthCalender or a DateTimePicker?
--- For example, I put a MonthCalender to my form and it shows the 2007-April month. How can I manage my software that shows me the "April 2007 has totally 30 days"
Last Visit: 31-Dec-99 18:00 Last Update: 30-Sep-23 0:58