I have this code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SharpDX.XInput;
using System.Threading;
using System.Reflection;
using System.Diagnostics;
namespace ControllerCheck
{
public partial class CheckForm : Form
{
public CheckForm()
{
InitializeComponent();
}
Graphics x;
private TimeSpan Redraw(object sender, EventArgs e)
{
var watch = Stopwatch.StartNew();
Bitmap b = new Bitmap(DisplayPanel.Width, DisplayPanel.Height);
Graphics g = Graphics.FromImage(b);
g.FillRectangle(Brushes.White, 0, 0, DisplayPanel.Width, DisplayPanel.Height);
g.FillRectangle(Brushes.Black, 0, 0, DisplayPanel.Width, DisplayPanel.Height);
x.DrawImageUnscaled(b, 0, 0);
watch.Stop();
return watch.Elapsed;
}
private async void CheckForm_Shown(object sender, EventArgs e)
{
Task.Run(() =>
{
x = DisplayPanel.CreateGraphics();
while (true)
{
var ts = Redraw(null, null);
Console.WriteLine("Zajęło to {0} ticków, czyli {1} ms", ts.Ticks, ts.TotalMilliseconds); //(It tooked {0} ticks or {1} ms)
}
});
}
}
}
I want to make small program to check XInput with SharpDX
But RAM usage goes to 2 GB and throws OutOfMemoryException on "x.DrawImageUnscaled(b, 0, 0)
" in Redraw (Look at screenshot)
I draw white and black rectangles to see if it's working, and it is, I see only black rectangle so RAM is the only problem