Avatar of Jeff Heilman
Jeff HeilmanFlag for United States of America

asked on 

C# Winforms Datarepeater issues.

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.
            }
        }

Open in new window

Thank you!
C#Microsoft Visual Studio

Avatar of undefined
Last Comment
Kelvin McDaniel
ASKER CERTIFIED SOLUTION
Avatar of Kelvin McDaniel
Kelvin McDaniel
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo