I want to show firstly my login form (FrmLogin) and if user correctly put his credentials to close FrmLogin and show main form (FrmMain) therefore i did following steps:

in Application.xaml instead of StartupUri i placed:

```
 Startup="Application_Startup">

```

then in Application.xaml.vb:

```
  Class Application

        Private Sub Application_Startup(sender As Object, e As StartupEventArgs)

            Dim result As New FrmLogin
            result.ShowDialog()

            If (result.DialogResult.HasValue And result.DialogResult.Value) Then
                    Dim FrmMain As New FrmMain()
        Run(FrmMain)
            Else
                MessageBox.Show("User clicked Cancel")
'closing application...
            End If

        End Sub

    End Class

```

in FrmLogin:

```
 Public Class FrmLogin
        Private Sub btnOk_Click(sender As Object, e As RoutedEventArgs) Handles btnOk.Click
            Me.DialogResult = True
        End Sub

        Private Sub btnCancel_Click(sender As Object, e As RoutedEventArgs) Handles btnCancel.Click
            Me.DialogResult = False
        End Sub
    End Class

```

unfortunetly i got errors on those lines in Applciation\_Startup:

```
  Dim FrmMain As New FrmMain()
        Run(FrmMain)

```

error message:

> 
> Additional information: Application is already running the Dispatcher.
> 
> 
> 

what i am doing wrong and what should i do? By the way is this approach correct?