当我单击很多次时,我的臀部会崩溃/冻结 [英] My buttom crashes / freezen when i click a lot of times
问题描述
你好
我正在Windows窗体中做一个项目,问题是当我在菜单的按钮中多次单击时,它在内存中出现了Mb的lof现象,第一张图片是我仅完成操作时的情况单击,在内存中有25MB,然后在第二张照片中 进行了将近50次点击,我获得了90 MB以上的空间:
I am doing a project in Windows Form, and the problem is that when i click a lot of times in a button of my menu, it get a lof of Mb in the memory, the first picture is when i have done only a click, with 25MB in the memory, then in the second photo i have done almost 50 clicks, and i get more of 90 MB:
{
LoginForm loginform = new LoginForm();
sql.authenticated = true;
authenticated.AddFormToPanel(loginform, panelcenter);
sql.authenticated = false;
}
^^是按钮的代码,它生成一个表单,该代码是:
^^ Is the code of the button, It generates a form, which code is:
using System;
using System.Windows.Forms;
namespace Marks_Gestionator
{
public partial class LoginForm : Form
{
public LoginForm()
{
InitializeComponent();
}
private void btConnect_Click(object sender, EventArgs e)
{
sql.login_sqlcmd(string.Format("SELECT password from users WHERE username = '{0}';", box_login_username.Text));
md5.MD5encode(box_login_password.Text);
if (sql.password == md5.passwordmd5)
{
MessageBox.Show("Connected.");
sql.authenticated = true;
}
else
{
MessageBox.Show("Password is not correct.");
sql.authenticated = false;
}
}
}
}
另一方面,我的应用发生崩溃,它的开头为30MB,
On the other hand, my app get a crash in other part, it starts with 30MB,
它向我报告了这个错误:
And it reports me this mistake:
推荐答案
您是否考虑过使用try/finally禁用按钮,以便在尝试之前禁用按钮,请在尝试中进行操作,最后再启用.
Have you considered disabling the button using a try/finally so that prior to the try, disable the button, do work in the try, re-enable in the finally.
当然,您可以取消订阅工作,然后通过尝试/最终设置再次订阅click事件.
Of course you could un-subscribe do work then subscribe back to the click event, again with a try/finally setup.
这篇关于当我单击很多次时,我的臀部会崩溃/冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!