首页 > 解决方案 > 如何修复错误:无法访问已处置的对象,对象名称:“图像”

问题描述

大家好,我有一个错误,但我不知道为什么它只是偶尔弹出,有时没有错误,有时还可以,现在可以了,我找不到这个错误到底在哪里,因为它可以,有时它在那里。

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'我真的不知道如何找到这个人,我将不胜感激,谢谢。

标签: c#winforms

解决方案


推荐阅读