익명 메서드를 통한 깔끔한 코딩~

 

 

Winform

        /// <summary>
        /// 관망 해석 중 Percent가 변경되면 발생합니다.
        /// </summary>
        /// <param name="value"></param>
        void global_PecentageChangedEvent(int value)
        {
            this.Invoke(new MethodInvoker(
                delegate()
                {
                    this.ts_proBar.Value = value;
                }
            )
            );
        }

        /// <summary>
        /// 관망 해석 시작 전 Percent 최소 최대값을 Callback 받습니다.
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        void global_InitProgressBarCallback(int min, int max)
        {
            this.Invoke(new MethodInvoker(
                delegate()
                {
                    this.ts_proBar.Minimum = min;
                    this.ts_proBar.Maximum = max;
                }
            )
            );
        }


 

 

 WPF

        private void btnTest1_Click(object sender, RoutedEventArgs e)
        {
            Thread thread = new Thread(UpdateButton);
            thread.Start();
        }
        public void UpdateButton()
        {
            if (this.btnTest2.Dispatcher.CheckAccess())
            {
                this.btnTest2.Content = "hi";
            }
            else
            {
                this.btnTest2.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                    (Action)delegate() { UpdateButton(); });
            }
        }


 

+ Recent posts