c# - 如何修复错误:无法访问已处置的对象,对象名称:“图像”
问题描述
大家好,我有一个错误,但我不知道为什么它只是偶尔弹出,有时没有错误,有时还可以,现在可以了,我找不到这个错误到底在哪里,因为它可以,有时它在那里。
if (globalVariables.sBarcodeValidation.IndexOf("Images") + 1 > 0)
{
globalVariables.aErrorDisp = globalVariables.sBarcodeValidation.Split('|');
globalVariables.gCN = globalVariables.aErrorDisp[1];
if (globalVariables.bOCR == true)
{
//Images.DefaultInstance.Show(); //technically this is the first code here but
Images image = new Images();//i replace it with this
image.Show();// and this
}
txtBarCode.Text = string.Empty;
return;
}
在第一页中,我将调用一个名为“Images”的表单表单,如果其中globalVariables.sBarcodeValidation
包含一个单词 Images,那么此代码将在 Images 表单内执行。
private void Images_Load(object sender, EventArgs e)
{
string sImageValidation = null;
string[] aImages = null;
int ctr = 0;
btnChange.Text = "Change Record to " + globalVariables.gCN;
sImageValidation = string.Empty;
int x = int.Parse(new ImagesRepository().GetContainers(Settings.Default.BoothID));
int j = 0;
ctr = 0;
for (j = 1; j <= x; j++)
{
sImageValidation = new ImagesRepository().GetWKCounter(Settings.Default.BoothID, j);
aImages = sImageValidation.Split(';');
ctr = dgTruckQueue.Rows.Count - 1;
dgTruckQueue.Rows.Insert(ctr, aImages[0], aImages[1], aImages[2], aImages[3], aImages[4]);
}
dgTruckQueue.Sort(dgTruckQueue.Columns[4], System.ComponentModel.ListSortDirection.Descending);
}
并在加载此代码后
我将单击名为“btnProceed”的按钮
private void btnProceed_Click(object sender, EventArgs e)
{
string sImageValidation = null;
if (globalVariables.ulevel == "In-Gate")
{
sImageValidation = new ImagesRepository().LogMegaports(globalVariables.gCN, "401");
}
else if (globalVariables.ulevel == "Out-Gate")
{
sImageValidation = new ImagesRepository().LogMegaports(globalVariables.gCN, "302");
}
globalVariables.bOCR = false;
Close();
}
我已经对此进行了多次测试,有时它会抛出错误, Cannot access a disposed object,Object name: 'Images'
我真的不知道如何找到这个人,我将不胜感激,谢谢。
解决方案
推荐阅读
- flutter - “bool”类没有实例方法“-”。接收者:true 尝试调用:-(false)
- syntax - 当我想引用枚举的变体时,有没有办法停止重复枚举的名称?
- node.js - Angular 和 Node + Express
- python - QLabel 正确定位文本轮廓
- html - 如何让孩子不继承动画属性
- android - 无法加载测试广告 Android
- linux - 搜索和重命名目录和子目录中的所有文件
- r - 排队包没有读取任何功能?
- android - ّ片段协程错误:无法在主线程上访问数据库,因为它可能会长时间锁定 UI
- jquery - 如何使用 Jquery 更新特定的 DataTable 单元格