2010-12-16 4 views
1

응용 프로그램 시작시 스플래시 sceen 레이블을 업데이트하여 사용자에게 무슨 일이 일어나는지 알려주는 가장 좋은 방법은 무엇입니까? 문제는 스플래시 화면이 override 메서드로 만들어지고, 업데이트는 "this.SplashScreen"에 액세스 할 수없는 정적 main 메서드 내에서 수행되어야한다는 것입니다.SingleInstanceApplication에서 스플래시 레이블 업데이트 : WindowsFormsApplicationBase

class SingleInstanceApplication : WindowsFormsApplicationBase 
{ 
    [STAThread] 
    static void Main(string[] args) 
    { 
     SetSplashInfo("Data configuration", "Applying DataDirectory"); 
     //Can't be done, this method is static** 
     //Do some stuff, code removed for reading purposes 
    } 

    protected override void OnCreateSplashScreen() 
    { 
     this.SplashScreen = new TestSplash(); 
     this.SplashScreen.TopMost = true; 

     base.OnCreateSplashScreen(); 
    } 

    private void SetSplashInfo(string txt1, string txt2) 
    { 
     if ( this.SplashScreen == null) 
      return; 
     TestSplash splashFrm = (TestSplash)this.SplashScreen; 
     splashFrm.label1.Text = txt1; 
     splashFrm.label2.Text = txt2; 
    } 
} 

답변

2

예, SingleInstanceApplication 개체에 대한 참조가 필요합니다. 오직 그들 중 하나가 있기 때문에, 당신은 속일 수

class SingleInstanceApplication : WindowsFormsApplicationBase { 
    private static SingleInstanceApplication instance; 
    public SingleInstanceApplication() { 
     instance = this; 
    } 
} 

지금 당신은 항상 시작 화면에 대한 참조를 얻을 SetSplashInfo를 만들기 위해 instance.SplashScreen을 사용할 수 있습니다() 정적. 깨끗한 수정이 가능해야하지만 어떻게 SingleInstanceApplication 인스턴스를 생성하는지 알 수 없습니다.

+0

고맙지 만 작동하지 않는 것 같습니다. 'instance'가 null 인 경우 (Main에서) 또는 'override void OnCreateMainForm'내에서 인스턴스에 액세스하는 경우 '크로스 스레드 연산이 유효하지 않습니다.'... –

+1

SingleInstanceApplication 객체를 만든 후 * 사용할 수 있습니다. 예, SplashScreen에서 BeginInvoke() 메서드를 사용해야합니다. 다른 스레드에서 실행됩니다. 도움이 필요하면 Control.BeginInvoke() 문서를 확인하십시오. –

+0

미안 .. 꽤 어리 석 었어 ...--). 모든 도움에 감사드립니다! –