C#
C# 쓰레드, 스레드(Thread) 에서 UI 변경, 접근 하기
캬옹냐옹
2021. 2. 5. 11:07
728x90
//동기 UI 접근
this.Invoke((System.Action)(() =>
{
this.Text = title;
//작업 할 코드
}));
//비동기 UI 접근
this.BeginInvoke((System.Action)(() =>
{
this.Text = title;
//작업 할 코드
}));
다른 접근 방법도 많지만 가장 간단한 방법이다.
안드로이드에서 사용 하는 runOnUiThread 같은 느낌이다.
혹시나 실행전에 예외 처리를 하고 싶다면 아래처럼 하면 된다.
if (this.InvokeRequired) //BeginInvoke 예외 처리
{
this.BeginInvoke((System.Action)(() =>
{
}));
}
728x90