程序内存检测

本文参考自:http://www.cnblogs.com/hebeiDGL/p/3410188.html

        static System.Windows.Threading.DispatcherTimer dispacherTimer;
        static string total = "DeviceTotalMemory";
        static string current = "ApplicationCurrentMemoryUsage";
        static string peak = "ApplicationPeakMemoryUsage";
        static long totlaBytes;
        static long currentBytes;
        static long peakBytes;

        public MainPage()
        {
            InitializeComponent();
            checkmemory();
        }
        void checkmemory() 
        {
            dispacherTimer = new System.Windows.Threading.DispatcherTimer();
            dispacherTimer.Interval = TimeSpan.FromSeconds(2);
            dispacherTimer.Tick += dispacherTimer_Tick;
            dispacherTimer.Start();
        }
        void dispacherTimer_Tick(object sender, EventArgs e)
        {
            // 获取设备的总内存
            totlaBytes = (long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue(total);

            // 获取应用当前占用内存
            currentBytes = (long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue(current);

            // 获取内存占用的峰值
            peakBytes = (long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue(peak);

            txtMemory.Text = string.Format("当前:{0:F2}MB;  峰值:{1:F2}MB;  总:{2:F2}MB;", currentBytes / (1024 * 1024.0), peakBytes / (1024 * 1024.0), totlaBytes / (1024 * 1024.0));
        }    

  

转载于:https://www.cnblogs.com/defoliate/p/3677765.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值