troubleshooting Question

C# Winforms Datarepeater issues.

Avatar of Jeff Heilman
Jeff HeilmanFlag for United States of America asked on
C#Microsoft Visual Studio
1 Comment1 Solution16 ViewsLast Modified:
I have a winform with a datarepeater that contains quite a few controls.  The problem I'm having is that after it refreshes a few times it crashes.  I used Process Explorer and saw that when USER OBJECTS reaches 10,000 for my application is when it locks up.

I think that this issue is because I have to rebind the controls over and over to refresh the data and not disposing them properly, but I'm not sure exactly how to do that.  Could anyone help me with a way to make this work?  Here is the code I have so far:
private void PopulateDataRepeater()
        {    
            //foreach(Control ctrl in dataRepeater1.Controls)
            //{
            //    ctrl.Dispose();  <<<<<<  THIS WAY OF DISPOSING DOES NOT WORK.
            //}
            try
            {
                Invoke((MethodInvoker)delegate
                {
                    dataRepeater1.BeginResetItemTemplate();

                    lblExtruder.DataBindings.Clear();
                    lblOldItem.DataBindings.Clear();
                    lblStatus.DataBindings.Clear();
                    lblAmps.DataBindings.Clear();
                    lblThermocoupler.DataBindings.Clear();
                    lblVibrationTemp.DataBindings.Clear();
                    lblDurationHrs.DataBindings.Clear();
                    lblBattery.DataBindings.Clear();
                    lblLastReading.DataBindings.Clear();
                    progressBarAmps.DataBindings.Clear();
                    progressBarThermocoupler.DataBindings.Clear();
                    progressBarVibrationTemp.DataBindings.Clear();

                    vw_sensors_current_statusTableAdapter.Fill(sensorsDataSet.vw_sensors_current_status);
                    dt.Clear();
                    dt = vw_sensors_current_statusTableAdapter.GetData();
                    
                    lblExtruder.DataBindings.Add(new Binding("Text", dt, "MachineID", true));
                    lblOldItem.DataBindings.Add(new Binding("Text", dt, "TopOfSched", true));
                    lblStatus.DataBindings.Add(new Binding("Text", dt, "ExtruderStatus", true));                    
                    lblAmps.DataBindings.Add(new Binding("Text", dt, "amps", true));
                    lblThermocoupler.DataBindings.Add(new Binding("Text", dt, "thermocoupler_temperature", true));
                    lblVibrationTemp.DataBindings.Add(new Binding("Text", dt, "vibration_temperature", true));
                    lblDurationHrs.DataBindings.Add(new Binding("Text", dt, "HrsDuration", true));
                    lblBattery.DataBindings.Add(new Binding("Text", dt, "BatteryStatus", true));
                    lblLastReading.DataBindings.Add(new Binding("Text", dt, "LastReading", true));
                    progressBarAmps.DataBindings.Add(new Binding("Value", dt, "amps", true));
                    progressBarThermocoupler.DataBindings.Add(new Binding("Value", dt, "thermocoupler_temperature", true));
                    progressBarVibrationTemp.DataBindings.Add(new Binding("Value", dt, "vibration_temperature", true));
                    
                    dataRepeater1.EndResetItemTemplate();

                    dataRepeater1.DataSource = dt;
                    dataRepeater1.Update();
                    dataRepeater1.Refresh();
                    //GC.Collect(0);
                    //Console.WriteLine("Garbage Collection in Generation 0 is: "
                    //                                  + GC.CollectionCount(0));  <<<<<THIS DOES NOT WORK EITHER
                });                              
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
            }
            finally
            {
                // *****Adding Finally block does not change anything.
            }
        }
Thank you!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros