BeginInvoke를 올바르게 사용하는 방법을 배우고 있습니다. 필자는 콘솔 앱에 작은 테스트를 작성하여 BeginInvoke를 사용하여 제목이 표시된 100x100 창을 만들기 위해 함수를 호출하는 방법을 사용합니다. 나는 비참하게 실패하고있다. 여기에 내가 가지고있는 것이 있는데, 이것이 아마도 스레드 (내 강점이 아닌)에 대한 이해가 부족한 것임을 알지만, 멈추지 않고 창을 팝업하지 않습니다. 키 누르기를 기다리는 Main의 readline에서 끝납니다. 실행은 ThreadUITest에서 시작됩니다.Dispatcher.BeginInvoke 올바른 사용법?
static void ThreadUITest()
{
ThreadStart starter = new ThreadStart(threadFunc1);
Thread test = new Thread(starter);
test.IsBackground = true;
test.SetApartmentState(ApartmentState.STA);
test.Start();
}
static void threadFunc1()
{
dispatcher = Dispatcher.CurrentDispatcher; //Statically declared earlier
ThreadStart starter = new ThreadStart(threadFunc2);
Thread test = new Thread(starter);
test.IsBackground = true;
test.Start();
}
static void threadFunc2()
{
Action method = Draw;
Console.WriteLine("I'm here!");
//dispatcher.BeginInvoke((Action)(() => {Draw();}),DispatcherPriority.Render, null);
dispatcher.BeginInvoke(method, DispatcherPriority.Send, null);
}
static void Draw()
{
Window win = new Window();
win.Height = 100;
win.Width = 100;
win.Title = "A Window!";
win.Show();
}
도움 주셔서 감사합니다.
'dispatcher.Invoke'를 사용할 때 작동합니까? –
아니요, 그렇지 않습니다. –