【发布时间】:2017-08-01 22:46:15
【问题描述】:
经过一番努力,我写了“游戏引擎”,我发现了一个非常奇怪的错误。 当您移动表单时,您会得到 OutOfMemory 异常(应用程序在不到 5 秒的时间内从需要 24 MB 的内存跳转到超过 6 GB 的内存),但这并不是最奇怪的事情。这仅在您向上移动表格时出现,在任何其他方向都不会发生任何事情。这是我编写的一段代码,其工作方式与我的应用程序相似,尽管在向上移动表单后会立即崩溃
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
Graphics h;
Bitmap bmp;
System.Threading.Thread WTF;
public Form1()
{
InitializeComponent();
}
private void LOL()
{
bmp = new Bitmap(500, 500);
Graphics WHAAAAT = Graphics.FromImage(bmp);
while (true)
{
WHAAAAT.FillEllipse(Brushes.Black, 50, 50, 50, 50);
h.DrawImage(bmp, 0, 0);
}
}
private void WOOT(Graphics g)
{
h = g;
WTF = new System.Threading.Thread(new System.Threading.ThreadStart(LOL));
WTF.Start();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics d = panel1.CreateGraphics();
d.FillEllipse(Brushes.Black, 50, 50, 50, 50);
WOOT(d);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
WTF.Abort();
}
}
}
表单边框样式设置为singleFixed。知道为什么会发生这种情况吗? 在我的情况下,它会引发由大量 RAM 使用引起的其他异常,但它也仅在您向上移动表单时出现
【问题讨论】:
-
你分析过它吗?
-
有一个名为 WTF 的变量是鼻恶魔的 c# 后门,这就是为什么会发生奇怪的事情:)
标签: c# multithreading winforms