Save last value in variable and display [duplicate]

0

I have a problem with my program and its function is to display on the screen how much RAM the process is consuming at the moment and display the peak of ram usage, so my problem is when I close the process, the program to display the peak of ram memory.

Here is the part of the code that displays the peak of ram memory:

        public string vmax()
    {

        System.Diagnostics.Process[] ieProcs = Process.GetProcessesByName(label92.Text);
       double avvv = 0;
       string abi = null;
        try
        {

                if (ieProcs.Length > 0)
                {
                    foreach (System.Diagnostics.Process p in ieProcs)
                    {
                        String physicalMem = p.PeakWorkingSet64.ToString();
                        abi = physicalMem;
                    }
                }

                avvv = double.Parse(abi);
               avvv = avvv * 0.001 / 1024;
            return avvv + " K";


        }
        catch
        {
            return "";
        }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        label90.Text = vmax();
    }

With the calculator process open:

Withthecalculatorprocessclosed:

I wanted that even when I closed the process it would still display the last value recorded by the peak.

    
asked by anonymous 17.04.2016 / 16:47

1 answer

1

Following the details given below, a change is made based on what you need. The idea for what I understand is to monitor the memory consumption of a process in your application, and register the highest checked value, if the process is finished your application should keep the highest value recorded so far, correct?

I created a small example form where I enter the process name (in my case calc).

SeethatinthePicolabelI'mshowingthehighestvalueregistered,thisisdonebythecodethatIaddedtoyourvmaxmethod:

if(avvv>valorMax)valorMax=avvv;lblPico.Text=valorMax+"K";

The above code was added immediately before return . Remembering to declare a variable in the class:

private double valorMax;

As I use the calculator windows (calc), the "current value" is being modified as well as the Pico (if the current is greater than the last recorded peak). Even if I close the process, ie close the calculator, the peak value is maintained and as soon as I reopen the process the peak will still be there.

Unless you wish to register this even though your application is finalized, I believe that it meets your need. In order to perpetuate this it would be enough to save the last peak in an xml or txt, and when the application reopens the value.

    
20.04.2016 / 15:57