Aşağıda, AdonisUI kullanarak bir RAM Temizleyici Uygulamasının WPF C# kod örneklerini bulabilirsiniz. Bu örnekte, fiziksel bellek bilgilerini göstermek için bir GroupBox ve bir ProgressBar ile kullanıcı dostu bir arayüz tasarlanmıştır.
Öncelikle AdonisUI nuget paketini projenize kurmanız gerekecektir. Visual Studio'nun Package Manager Console'una Install-Package AdonisUI -Version 1.14.1 komutunu girerek AdonisUI'yi projenize ekleyebilirsiniz.
XAML dosyasın (örneğin MainWindow.xaml) yapılandırma örneği:
<adonisUi:AdonisWindow x:Class="ShadesTweaker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:adonisUi="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ShadesTweaker"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="UnleashRAM" Height="450" Width="800">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<GroupBox Header="Physcial Memory Info" Grid.Column="0" Padding="5">
<StackPanel>
<TextBlock x:Name="TotalMemoryText" />
<TextBlock x:Name="UsedMemoryText" />
<TextBlock x:Name="FreeMemoryText" />
<ProgressBar x:Name="MemoryProgressBar" Height="20" Margin="0,10" />
</StackPanel>
</GroupBox>
<Button Content="Optimize" Grid.Column="1"
VerticalAlignment="Bottom"
Height="30" Width="100"
Margin="10"
Click="OptimizeButton_Click" />
</Grid>
</adonisUi:AdonisWindow>
C# Code-Behind dosyası (MainWindow.xaml.cs) örneği:
using AdonisUI.Controls;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Threading;
namespace ShadesTweaker
{
public partial class MainWindow : AdonisWindow
{
private DispatcherTimer _timer;
public MainWindow()
{
InitializeComponent();
_timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(1)
};
_timer.Tick += Timer_Tick;
_timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
UpdateMemoryInfo();
}
private void UpdateMemoryInfo()
{
// Önce bilgisayarınızın bellek bilgilerini alın
PerformanceCounter pc = new PerformanceCounter("Memory", "Available MBytes");
double freeMemory = pc.NextValue();
double totalMemory = new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory / (1024 * 1024);
double usedMemory = totalMemory - freeMemory;
// Ardından bilgileri arayüze aktarın
TotalMemoryText.Text = $"Total Memory: {totalMemory} MB";
UsedMemoryText.Text = $"Used Memory: {usedMemory} MB";
FreeMemoryText.Text = $"Free Memory: {freeMemory} MB";
// ProgressBar için değerleri güncelleyin
MemoryProgressBar.Maximum = totalMemory;
MemoryProgressBar.Value = usedMemory;
}
private void OptimizeButton_Click(object sender, RoutedEventArgs e)
{
// Bellek temizleme işlevi burada gerçekleştirilebilir
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}
Bu örneklerde PerformanceCounter ve Microsoft.VisualBasic.Devices.ComputerInfo sınıfları kullanılmıştır. Bu sınıfların çalışması için projenize System.Diagnostics ve Microsoft.VisualBasic assembly referanslarını eklemeniz gerekmektedir. Ve GC.Collect() çağrısı sınırlı bir temizlik sağlar; örneğin .NET tarafından yönetilen bellek için garip toplayıcıyı çalıştırır ancak işletim sistemi düzeyinde daha derin bir hafıza temizliği için başka araçlar veya yöntemler gerekebilir.