스플래시 화면을 표시하기 위해 WindowsFormsApplicationBase을 사용하고 있습니다. 이제 주 폼이 만들어지고 오류가 발생하면 사용자에게 알리는 메시지 상자가 표시되어야합니다. 그러나 메시지 상자는 시작 화면 아래에 표시되므로 보이지 않습니다. 사용자와 상호 작용할 수 있도록 스플래시 화면을 닫아야합니다.다른 스레드에서 시작 화면을 닫으시겠습니까?
이class SingleInstanceApplication : WindowsFormsApplicationBase
{
private static SingleInstanceApplication instance;
public static void CloseSplash()
{
if (instance.SplashScreen != null)
instance.SplashScreen.Close();
}
}
오류 :
다음 코드는 스레드 간 연산 예외 줄 것이다
Cross-thread operation not valid: Control 'Splash' accessed from a thread
other than the thread it was created on.
이 가능하다조차를?
이 작업을 수행하는 일반적인 방법은 UI 스레드에서 SynchronizationContext를 얻을 수 SynchronizationContext.Current을 사용하는 것입니다. 그런 다음 백그라운드 나 다른 스레드에서 작동하는 모든 것으로 전달합니다. 그러면 UI 스레드를 통해 대리인을 게시 할 수 있습니다. – Will