Click here to Skip to main content
15,885,914 members
Articles / Programming Languages / C#

Event Handling and Garbage Collection in .NET

Rate me:
Please Sign up or sign in to vote.
4.85/5 (13 votes)
18 Nov 2009CPOL8 min read 47.4K   484   42  
An article that looks at the interplay between Event Handling and Garbage Collection
namespace EventHandlerDemo
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.buttonGenerate = new System.Windows.Forms.Button();
            this.listBox1 = new System.Windows.Forms.ListBox();
            this.panel1 = new System.Windows.Forms.Panel();
            this.radioRemove = new System.Windows.Forms.RadioButton();
            this.radioDispose = new System.Windows.Forms.RadioButton();
            this.radioDoNothing = new System.Windows.Forms.RadioButton();
            this.label1 = new System.Windows.Forms.Label();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // buttonGenerate
            // 
            this.buttonGenerate.Location = new System.Drawing.Point(13, 333);
            this.buttonGenerate.Name = "buttonGenerate";
            this.buttonGenerate.Size = new System.Drawing.Size(75, 23);
            this.buttonGenerate.TabIndex = 1;
            this.buttonGenerate.Text = "Generate";
            this.buttonGenerate.UseVisualStyleBackColor = true;
            this.buttonGenerate.Click += new System.EventHandler(this.Generate_Click);
            // 
            // listBox1
            // 
            this.listBox1.FormattingEnabled = true;
            this.listBox1.Location = new System.Drawing.Point(13, 76);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(446, 251);
            this.listBox1.TabIndex = 2;
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.radioRemove);
            this.panel1.Controls.Add(this.radioDispose);
            this.panel1.Controls.Add(this.radioDoNothing);
            this.panel1.Controls.Add(this.label1);
            this.panel1.Location = new System.Drawing.Point(13, 13);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(446, 57);
            this.panel1.TabIndex = 4;
            // 
            // radioRemove
            // 
            this.radioRemove.AutoSize = true;
            this.radioRemove.Location = new System.Drawing.Point(211, 21);
            this.radioRemove.Name = "radioRemove";
            this.radioRemove.Size = new System.Drawing.Size(136, 17);
            this.radioRemove.TabIndex = 3;
            this.radioRemove.Text = "Remove Event Handler";
            this.radioRemove.UseVisualStyleBackColor = true;
            // 
            // radioDispose
            // 
            this.radioDispose.AutoSize = true;
            this.radioDispose.Location = new System.Drawing.Point(130, 21);
            this.radioDispose.Name = "radioDispose";
            this.radioDispose.Size = new System.Drawing.Size(63, 17);
            this.radioDispose.TabIndex = 2;
            this.radioDispose.Text = "Dispose";
            this.radioDispose.UseVisualStyleBackColor = true;
            // 
            // radioDoNothing
            // 
            this.radioDoNothing.AutoSize = true;
            this.radioDoNothing.Checked = true;
            this.radioDoNothing.Location = new System.Drawing.Point(7, 21);
            this.radioDoNothing.Name = "radioDoNothing";
            this.radioDoNothing.Size = new System.Drawing.Size(79, 17);
            this.radioDoNothing.TabIndex = 1;
            this.radioDoNothing.TabStop = true;
            this.radioDoNothing.Text = "Do Nothing";
            this.radioDoNothing.UseVisualStyleBackColor = true;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(4, 4);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(109, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Select Program Mode";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(470, 368);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.listBox1);
            this.Controls.Add(this.buttonGenerate);
            this.Name = "Form1";
            this.Text = "Event Handling Demo";
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button buttonGenerate;
        private System.Windows.Forms.ListBox listBox1;
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.RadioButton radioRemove;
        private System.Windows.Forms.RadioButton radioDispose;
        private System.Windows.Forms.RadioButton radioDoNothing;
        private System.Windows.Forms.Label label1;

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
United Kingdom United Kingdom
David has been developing for a number of years, first in C++, and more recently on .NET. Having lived in London for several years where he worked on share trading systems in the early days of electronic trading, David has now returned to his home city of Sheffield and is developing software for the rail industry.

Comments and Discussions