Invoke with Anonymous Methods

From Yefu's notes
Jump to: navigation, search
        /// <summary>
        /// Changes the temperature.
        /// </summary>
        /// <param name="temp">The temp.</param>
        private void ChangeTemperature(float temp)
        {
            Debug.WriteLine(temp);
            // Don't do anything if the form's handle hasn't been created 
            // or the form has been disposed.
            if (!this.IsHandleCreated && !this.IsDisposed) return;

            this.Invoke((MethodInvoker)delegate()
            {
                    this.textBox_temperature.Text = temp.ToString();
            });
        }