2012-05-02 1 views
0

Symbol MC50에서 Compact Framework 3.5를 사용하고 있습니다.Sub Main 외부에서 호출 할 때 Application.Run (New myForm())이 작동하지 않습니다.

내 Sub Main에서는 먼저 데이터베이스가 있는지 확인합니다. 내가 frmMain 수 닫을 때 예상대로 응용 프로그램을 종료,이 모두가 제대로 작동

Dim login As frmLogin = New frmLogin() 
    If login.ShowDialog() = DialogResult.OK Then    
     Application.Run(New frmMain()) 
    End If 

과 : 그것은 않을 경우, 다음과 같은 코드를 사용하여 로그인 화면을 보여줍니다.

그러나 Sub Main에서 데이터베이스 검사가 실패하면 라이브 서버에서 데이터베이스를 만들고 채우는 데 사용되는 다른 형식의 ShowDialog() 메서드를 호출합니다. 다음은이 양식을 호출하는 코드는 다음과 같습니다

If Not File.Exists(SETTINGS_LOCALDB) Then 
     databaseExists = False 
     MessageBox.Show("Local DB does not exist. The database must be created before using the application.") 
     Dim update As frmUpdateData = New frmUpdateData() 
     update.ShowDialog() 
Else 
    ..... 
End If 

내가 frmUpdateData가 실행되지 않은 하위 홈페이지의 코드의 나머지 부분을 닫을 때, 따라서 Application.Run 명중되고 있지 않았던 것입니다했다 첫 번째 문제.

If SystemUserSecurityId() = Nothing Then 
     Dim login As frmLogin = New frmLogin() 
     If login.ShowDialog() = DialogResult.OK Then 
      DebugTrace("Init - login complete, starting application.") 
      Application.Run(New frmMain()) 
     End If 
    End If 
    Me.Hide() 

이 코드의 모든 명중되고 있으며 frmMain 수 실제로 부하를 수행합니다

그래서 frmUpdateData에 닫기 버튼의 클릭 이벤트에 다음 코드를 추가했습니다. 그러나 오른쪽 상단의 닫기 버튼을 클릭해도 아무 일도 발생하지 않고 이벤트가 발생하지 않습니다. 마치 Windows 이벤트가 발생하지 않는 것입니다.

내가 잘못 했습니까?

+1

이것이 도움이 될지 모르겠지만 사용하려고합니다. Application.Run은 ShowDialog를 호출하는 대신 frmLogin 및 frmUpdateData 양식을 표시합니다. 응용 프로그램 메시지 루프에 있지 않을 때 .NET이 대화 상자 및 메시지 상자를 표시하는 데 얼마나 친절하게 사용되는지 알 수 없습니다. –

답변

1

이유 기본 형태는하지 않습니다 닫기는 응용 프로그램이 대화 상자의 닫는 이벤트의 호출 스택에 "붙어 있기"때문입니다. 즉, 기본 양식에 대한 Windows 메시지 루프를 시작한 곳이기 때문입니다.

코드를 약간 재구성하는 것이 좋습니다.

Application.Run(New frmMain()) 

이 기본 폼에 타이머를 삭제하고 매우 빠른 간격 (예를 들어 10 밀리 초) 설정 :

대신에 "주"하위에서 유효성 검사를 수행하는 대신 기본 양식을로드합니다. 기본 폼의로드 이벤트에서이를 활성화하십시오. 그런 식으로 틱 이벤트 처리기를 구현하십시오 (내 VB 구문이 아마도 완벽하지는 않습니다. 여기에 날개 달기가 있습니다).

Sub TmrOneShot_Tick(ByVal sender as Object, ByVal e as System.EventArgs) 
    'prevent timer from firing again. 
    tmrOneShot.Enabled = False; 
    Dim bContinue as Boolean = False; 

    If Not File.Exists(SETTINGS_LOCALDB) Then 
     databaseExists = False 
     MessageBox.Show("Local DB does not exist. The database must be created before using the application.") 
     Dim update As frmUpdateData = New frmUpdateData() 
     update.ShowDialog() ' Is this what populates your database??? 

     'analyze result of update form to determine if you should continue... 
     bContinue = WasUpdateDataOperationSuccessful(); 

    End If 

    If bContinue Then 
     If SystemUserSecurityId() = Nothing Then 
     Dim login As frmLogin = New frmLogin() 
     bContinue = login.ShowDialog() = DialogResult.OK 
     if bContinue Then 
      DebugTrace("Init - login complete, starting application.")    
     End If 
     End If 
    End If 

    If Not bContinue Then 
    'can't continue, terminate app 
    Application.Exit() 
    End if 
End Sub 
1

내가 응용 프로그램의 전체 조립하는 방법을 볼 수 없습니다,하지만 난 "다른"절을 제거하여이 작은 변화를 제안합니다 :

If Not File.Exists(SETTINGS_LOCALDB) Then 
    databaseExists = False 
    MessageBox.Show("Local DB does not exist. The database must be created before using the application.") 
    Dim update As frmUpdateData = New frmUpdateData() 
    update.ShowDialog() ' Is this what populates your database??? 
' Else (removed the else clause) 
End If 
If File.Exists(SETTINGS_LOCALDB) Then ' now it is OK to run, correct? 
    If SystemUserSecurityId() = Nothing Then 
    Dim login As frmLogin = New frmLogin() 
    If login.ShowDialog() = DialogResult.OK Then 
     DebugTrace("Init - login complete, starting application.") 
     Application.Run(New frmMain()) 
    End If 
    End If 
End If 
관련 문제