表单控件越来越被创建的窗体后不久自动处理 [英] Form Control getting disposed automatically shortly after form being created

查看:183
本文介绍了表单控件越来越被创建的窗体后不久自动处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个奇怪的和不一致的问题。

I have this weird and inconsistent issue.

应用程序内置在紧凑的框架3.5的Windows Mobile 6.5设备上运行。

The application is built in compact framework 3.5 running on a windows mobile 6.5 device.

应用程序的屏幕流是有点像这样。

The screen flow of the application is somewhat like this.

MainScreen(这是始终运行) 屏蔽1 画面2 屏幕3

MainScreen (which is always running) Screen1 Screen2 Screen3

MainsScreen - >屏蔽1 - >画面2 - >屏幕3 - > MainScreen

MainsScreen -> Screen1 -> Screen2 -> Screen3 -> MainScreen

在循环完成,应用程序的土地重新MainScreen,MainScreen.Activated()被调用,并在条件自动启动屏蔽1。 在code看起来是这样的:

When the loop is completed and the application lands back on MainScreen, MainScreen.Activated() is called and on a condition launches automatically Screen1. The code looks something like this:

        private void MainScreen_Activated(object sender, EventArgs e)
    {
        if (Condition)
        {
            NextScreen();

            return;
        }

            //other code here

    }
    private void NextScreen()
    {

        Screen1 formScreen1 = new Screen1 ();
        formScreen1 .Show();
    }

屏蔽1也有这块code形式的负载:

Screen1 has also this piece of code in the load of the form:

 private void Screen1_Load(object sender, System.EventArgs e)
{
        if(Condition)
        {
             NextScreen();
        }
}
 private void NextScreen()
    {

        Screen2 formScreen2=  new Screen2();
        formScreen2.Show();

        Close();
    }

所以,当这个条件Screen1_Load被满足应用程序会自动启动屏幕2并关闭。

So when this condition in Screen1_Load is fulfilled the application automatically launches Screen2 and closes this.

在这种特殊情况下它发生,有时在画面2控件创建窗体后得到处理。我知道这是因为我可以清楚地看到在屏幕上瞬间控制。

In this particular case it happens that sometimes a control on Screen2 gets disposed after the form is created. I know this because i can actually see the control for a split second on the screen.

这个问题也不一致,也不会发生在确切的情况这使我相信这是一定要带的东西时机不好所有的时间。 那得到处理的控制似乎也随意选择,大部分时间是相同的按钮,但有时候,从表单列表框得到处理的情况。

The issue is also inconsistent, it won't happen all the time in the exact scenario which makes me believe it's got to something with bad timing. The control that gets disposed seems to be also chosen at random, most of the times it's the same button but there were cases when a listbox from the form got disposed.

请注意,没有code中,将调用处理控制的应用程序。

Please note that there is no code in the application that will call dispose of the control.

任何帮助是极大的AP preciated。谢谢你,希望我解释这个问题不够好。

Any help is greatly appreciated. Thank you, hope i explained the issue well enough.

推荐答案

我找到了原因和解决我的问题。 经过一番调查,我发现被设置的按钮被正好与在调试这个机会异常情况发生:

I found the cause and a solution to my issue. After much investigation i found out that the button being disposed was coinciding with this chance exception happening in debug:

A first chance exception of type 'System.ObjectDisposedException' occurred in System.Drawing.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.Drawing.dll

我还发现,这个机会异常会发生当设备或认为它的运行内存使GC运行,并试图清除内存。

I also found out that this chance exception can happen when the device is or thinks it's running out of memory causing the GC to run and try to clear memory.

我用了这个问题的答案 <一href="http://stackoverflow.com/questions/282327/net-compact-framework-can-i-$p$pvent-garbage-collector-to-stop-some-of-my-threa">$p$pvent垃圾收集器还增加GC.KeepAlive说患了这个问题的形式。

I used the answer to this question Prevent Garbage Collector and also added GC.KeepAlive on the form that were suffering this issue.

的机会异常仍然发生在调试在同一时间,但我一直无法从那以后重现该问题。

The chance exception still happens in debug at the same time but i haven't been able to reproduce the issue since then.

这篇关于表单控件越来越被创建的窗体后不久自动处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆