Kod:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace ramtemizleyici
{
public partial class Main : Form
{
[DllImport ( "psapi" )]
public static extern int EmptyWorkingSet ( IntPtr handle );
**** SetFree ()
{
Process [] process = Process.GetProcesses ();
long mem = 0;
foreach ( Process p in process ) mem += p.WorkingSet64;
PrintLog ( String.Format ( "Boşaltmadan önce kullanılam ram miktarı: {0:0}MB", mem / 1000.0f / 1000.0f ) );
mem = 0;
foreach ( Process p in process ) try { EmptyWorkingSet ( p.Handle ); } catch { }
process = Process.GetProcesses ();
foreach ( Process p in process ) mem += p.WorkingSet64;
PrintLog ( String.Format ( "Boşaltma sonrasında ram miktarı: {0:0}MB", mem / 1000.0f / 1000.0f ) );
}
**** PrintLog ( string log )
{
log = "[" + DateTime.Now.ToString("MM-dd hh:mm:ss") + "]" + log;
Log.Items.Add ( log );
Log.SelectedIndex = Log.Items.Count - 1;
}
public Main ()
{
InitializeComponent ();
PrintLog ( "Bellek boşaltıldı" );
}
private **** chkFree_CheckedChanged ( object sender, EventArgs e )
{
tmrFree.Enabled = chkFree.Checked;
}
private **** btnFree_Click ( object sender, EventArgs e )
{
SetFree ();
}
private **** tmrFree_Tick ( object sender, EventArgs e )
{
SetFree ();
}
private **** lstLog_SelectedIndexChanged(object sender, EventArgs e)
{
}
private **** Main_Load(object sender, EventArgs e)
{
}
private **** comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private **** progressBar2_Click(object sender, EventArgs e)
{
}
private **** tmrDeger_Tick(object sender, EventArgs e)
{
float cpuYuzde = islemci.NextValue();
label2.Text = cpuYuzde.ToString();
pbCPU.Value = (int)cpuYuzde;
float ramYuzde = ram.NextValue();
label1.Text = ramYuzde.ToString();
pbRAM.Value = (int)ramYuzde;
}
}
}
