Beispiel #1
0
        private void buttonRun_Click(System.Object sender, System.EventArgs e)
        {
            Cursor = Cursors.WaitCursor;


            // Garbage collection is forced to "clean" the heap, then
            // we pause while waiting for the separate finalizer thread
            // to clear the finalization queue. A final GC.Collect()
            // call clears out anything that may have been resurrected
            // by the finalizer.
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();

            MEMORYSTATUSEX ms = new MEMORYSTATUSEX();

            ms.Init();
            NativeMethods.GlobalMemoryStatusEx(ref ms);

            int pressure = _allocation;

            treeMain.Nodes.Clear();

            for (int i = 0; i < numericAllocations.Value; i++)
            {
                int nodeElement = treeMain.Nodes.Add(new TreeNode(String.Format(CultureInfo.InvariantCulture, "Allocating 1/{0} for the {1}{2} time", _allocation, i + 1, GetSuffix(i))));

                MemoryHogger m  = new MemoryHogger(pressure, radioPressureYes.Checked);
                TreeNode     tn = new TreeNode();

                if (m.Success)
                {
                    tn.Text      = "\tAllocation Succeeded!";
                    tn.BackColor = Color.FromArgb(0, 255, 0);
                    treeMain.Nodes[nodeElement].Nodes.Add(tn);
                }
                else
                {
                    tn.Text      = "\tAllocation Failed!";
                    tn.BackColor = Color.Red;
                    treeMain.Nodes[nodeElement].Nodes.Add(tn);
                }
                tn.Parent.Expand();
            }
            _curCount           = GC.CollectionCount(0) - _gcBaseLine - _totCount;
            _totCount           = GC.CollectionCount(0) - _gcBaseLine;
            labelCount.Text     = _curCount.ToString(CultureInfo.InvariantCulture);
            labelTotCount.Text  = _totCount.ToString(CultureInfo.InvariantCulture);
            buttonClear.Enabled = true;
            Cursor = Cursors.Arrow;
        }
        private void RefreshFromSettings()
        {
            var enabled = _optionService.GetOption(Enabled);

            if (_hogger != null)
            {
                _hogger.Cancel();
                _hogger = null;
            }

            if (enabled)
            {
                _hogger = new MemoryHogger();
                _       = _hogger.PopulateAndMonitorAsync(_optionService.GetOption(SizeInMegabytes));
            }
        }
        private void RefreshFromSettings()
        {
            var enabled = _optionService.GetOption(Enabled);

            if (_hogger != null)
            {
                _hogger.Cancel();
                _hogger = null;
            }

            if (enabled)
            {
                _hogger = new MemoryHogger();
                var ignore = _hogger.PopulateAndMonitorAsync(_optionService.GetOption(SizeInMegabytes));
            }
        }