私は完全に処分されないフォームメニューを持っています。以下は完全なフォームコードです。これは大きなシステムの一部なので、メニューが最初に開く前に他のフォームが開いたり閉じたりします。Winformは完全に処理されません
毎秒発生するフォームタイマーがあり、フォームの廃棄の有無が表示されます。別のフォーム、検索を開き、メニューを閉じるボタンがあります。検索には、それが廃棄されているかどうかを表示するタイマーもあります。
メニューが開いたら、私がクリックすると、デバッグ出力が期待通り
*********** (in main menu): Disposed False
*********** (in main menu): Disposed False
、私はタイマーは、両方のメニューのためのダニ取得し、
*********** (in main): Disposed True
*************** (in search) Disposed False
を検索されることがメニューの最初のインスタンスがあることを示していますしかし明らかにタイマーはまだ動いている。私は、検索終了し、メインが開かれると、今
*********** (in main): Disposed True
*********** (in main): Disposed False
私はこれをやり続けることができ
を実行している2つのメインのタイマーがあると増加し続ける実行している主なタイマーの数(検索して終了をクリックして開きます)。私は困惑している。ここでは、/フォームクラスのDesigner.csファイルの内容を貼り付けたコピーのように見えます
メインusing System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
namespace Gui
{
public partial class Menu : Form
{
private System.Windows.Forms.Timer timer1;
private Button button1;
private IContainer components;
public Menu()
{
InitializeComponent();
}
private void Menu_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
Debug.Print("*********** (in main): Disposed {0}", IsDisposed);
}
private void button1_Click(object sender, EventArgs e)
{
var search = new Search();
search.Show();
Close();
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// button1
//
this.button1.Location = new System.Drawing.Point(11, 17);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(125, 32);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Menu
//
this.ClientSize = new System.Drawing.Size(282, 253);
this.Controls.Add(this.button1);
this.Name = "Menu";
this.Load += new System.EventHandler(this.Menu_Load);
this.ResumeLayout(false);
}
}
}
フォームを参照し続けますか?どのようにそれを処分することができますか? – TaW
メインフォームを再オープンする 'Search'のコードを表示してください。私の推測では、既存のインスタンスを再度表示するのではなく、フォームの新しいインスタンスを作成しているということです。特に、あなたはそれを隠すのではなく、その上でクローズするからです。 –
@TaW - 処分は参照することとは関係ありません。 –