프로그래밍
C# worker 스레드에서 UI 스레드 Dispatcher 이용하기.
벌커덕스
2011. 6. 23. 10:31
UI 스레드에 갱신요청하기 위해 아래처럼 대리자, 콜러, 본체로 나눠서 코딩하다가 간단하게 할수 있는 방법을 발견 !!
윈폼 ----------------------------
WPF ----------------------------
------------------------------------
Invoke : 동기
BeginInvoke : 비동기
------------------------------------
public delegate void ShowButtonDelegate(bool IsShow); public void ShowButtonCaller(bool IsShow) { if (canvasButtonGroup.Dispatcher.CheckAccess()) ShowButtonBody(IsShow); else Dispatcher.Invoke(new ShowButtonDelegate(ShowButtonBody), IsShow); } private void ShowButtonBody(bool IsShow) { DebugWrite("ShowButtonBody =" + IsShow.ToString());------------------------------------
}
윈폼 ----------------------------
this.Invoke(new MethodInvoker(delegate() { mnuConnectServer.Enabled = true; mnuStartServer.Enabled = true; }));------------------------------------
WPF ----------------------------
MainUI.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
new DispatcherOperationCallback(delegate { MainUI.ResetGame(user.m_nID); return null;
}), null);
------------------------------------
Invoke : 동기
BeginInvoke : 비동기
------------------------------------