Example #1
0
        private void TestDisposeButton_Click(object sender, RoutedEventArgs e)
        {
            LogTextBox.Text = "Please wait...";
            var success = System.Threading.ThreadPool.QueueUserWorkItem(TestDispose);

            if (!success)
            {
                ProgressBarPanel.UpdateProgress("Scan failed!", "", true);
            }
        }
Example #2
0
        void TestDispose(object state)
        {
            var text = TestMemoryLeakAssemblies(
                typeof(App).Assembly,
                typeof(Engine.EngineHelper).Assembly
                );

            ControlsHelper.Invoke(() =>
            {
                ProgressBarPanel.UpdateProgress();
                LogTextBox.Text = text;
            });
        }
Example #3
0
 public DebugControl()
 {
     InitHelper.InitTimer(this, InitializeComponent);
     if (ControlsHelper.IsDesignMode(this))
     {
         return;
     }
     ProgressBarPanel.UpdateProgress();
     _TestTimer           = new HiResTimer(1, "TestTimer");
     _TestTimer.AutoReset = true;
     CpuTimer             = new System.Timers.Timer();
     CpuTimer.Interval    = 1000;
     CpuTimer.AutoReset   = false;
     CpuTimer.Elapsed    += CpuTimer_Elapsed;
     LoadSettings();
     CheckTimer();
 }
Example #4
0
        private void SwapItemsOnUI(int firstPos, int secondPos)
        {
            Color tmpColor = values[firstPos].Bar.Color;

            SetColorItemsOnUI(firstPos, secondPos, Color.Red);

            var BarTmpLocation = values[firstPos].Bar.Location;
            var BoxTmpLocation = values[firstPos].Box.Location;

            values[firstPos].Bar.Location = values[secondPos].Bar.Location;
            values[firstPos].Box.Location = values[secondPos].Box.Location;

            values[secondPos].Bar.Location = BarTmpLocation;
            values[secondPos].Box.Location = BoxTmpLocation;

            ProgressBarPanel.Refresh();
            Thread.Sleep(10);

            SetColorItemsOnUI(firstPos, secondPos, tmpColor);
            ProgressBarPanel.Refresh();
        }
Example #5
0
        public string TestMemoryLeakAssemblies(params System.Reflection.Assembly[] assemblies)
        {
            var log           = new List <string>();
            var disposedCount = 0;
            var aliveCount    = 0;
            var errorsCount   = 0;
            var e             = new ProgressEventArgs();

            for (int a = 0; a < assemblies.Length; a++)
            {
                var assembly = assemblies[a];
                e.TopCount   = assemblies.Length;
                e.TopIndex   = a;
                e.TopData    = assemblies;
                e.TopMessage = $"Assembly: {assembly.FullName}";
                ControlsHelper.Invoke(() => ProgressBarPanel.UpdateProgress(e));
                var types = assembly.GetTypes();
                for (int t = 0; t < types.Length; t++)
                {
                    var type = types[t];
                    e.SubCount   = types.Length;
                    e.SubIndex   = t;
                    e.SubData    = types;
                    e.SubMessage = $"Type: {type.FullName}";
                    ControlsHelper.Invoke(() => ProgressBarPanel.UpdateProgress(e));
                    if (type.IsInterface)
                    {
                        continue;
                    }
                    if (!type.FullName.Contains(".Controls.") && !type.FullName.Contains(".Forms."))
                    {
                        continue;
                    }
                    ControlsHelper.Invoke(() =>
                    {
                        try
                        {
                            var o  = Activator.CreateInstance(type);
                            var wr = new WeakReference(o);
                            // Verify that the WeakReference actually points to the intended object instance.
                            if (wr.Target.Equals(o))
                            {
                                // Dispose object.
                                o = null;
                                for (int i = 0; i < 4; i++)
                                {
                                    GC.Collect();
                                    GC.WaitForPendingFinalizers();
                                    GC.WaitForFullGCComplete();
                                    GC.Collect();
                                }
                                // Note: Debug mode turns off a lot of optimizations, because compiler is trying to be helpful.
                                // Debug build can keep values rooted even if you set them to null i.e. wr.IsAlive will always return TRUE.
                                if (wr.IsAlive)
                                {
                                    log.Add($"Is Alive: {type.FullName}");
                                    aliveCount++;
                                }
                                else
                                {
                                    log.Add($"Disposed: {type.FullName}");
                                    disposedCount++;
                                }
                            }
                            else
                            {
                                log.Add($"Error: NOT same as {type.FullName}");
                                errorsCount++;
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Add($"Error: {type.FullName} {ex.Message}");
                            errorsCount++;
                        }
                    });
                }
            }
            var results = $"Disposed = {disposedCount}, Alive = {aliveCount}, Errors = {errorsCount}\r\n" + string.Join("\r\n", log);

            return(results);
        }
Example #6
0
 void ConfigPlaybackBarControlColor()
 {
     ProgressBarPanel.CreateGraphics().Clear(ProgressBarPanel.BackColor);
     ProgressBarPanel.CreateGraphics().FillRectangle(Brushes.DarkSlateGray, new Rectangle(0, 0, ChangedProgressPanel.Left, ProgressBarPanel.Height));
 }