명령 창에 텍스트를 인쇄하는 콘솔 응용 프로그램이 있다고 가정합니다. 또한 출력을 복제해야하는 Logger WPF 창이 있습니다. IDE는 새 스레드 (STA) 내부의 창을 만들 나를 강제 : 스레드가 시작된 후콘솔 응용 프로그램에서 UI 요소에 액세스하는 방법
public SomeClass()
{
var loggerThread = new Thread(() =>
{
var logWindow = new Window
{
Title = "Logger", Width = 100, Height = 100
};
var stackPanel = new StackPanel
{
Name = "stackPanel"
};
stackPanel.Children.Add(new TextBlock
{
Name = "textBlock", Text = "new text\n"
});
logWindow.Content = stackPanel;
logWindow.ShowDialog();
});
loggerThread.SetApartmentState(ApartmentState.STA);
loggerThread.IsBackground = true;
loggerThread.Start();
}
public void PutInfo(string msg)
{
// how to access textBlock here?
...textBlock.Text = "some info";
}
가 어떻게 textBlock.Text에 액세스 할 수 있습니다. 즉, PutInfo() 메소드를 통해 다른 클래스의 해당 스레드에서 UI 요소에 액세스하는 방법은 무엇입니까?
당신은 라인의 몇 여기 교차 한
검색을 사용하여
Description
을 변경합니다. 알아두기 이것은 예 : http://stackoverflow.com/questions/11625208/accessing-ui-main-thread-safely-in-wpf – Andre