Quote Originally Posted by t0ret0s View Post
The idea is to check some files into the computer, in case the exact file is missing, I want to let user select it.
This is the first approach code :

Code:
        Dim worker = DirectCast(sender, BackgroundWorker)

        'Simulate some time-consuming work.
        For i = 0 To 100
            If worker.CancellationPending Then
                e.Cancel = True

                Exit For
            End If

            If reportProgressCheckBox.Checked Then
                worker.ReportProgress(i)
            End If

            If i = 50 Then

                If MsgBox("Do you want to select it manually ?", CType(vbYesNo + vbQuestion, Global.Microsoft.VisualBasic.MsgBoxStyle), "test test test test") = vbYes Then
                    Dim myStream As Stream = Nothing
                    Dim openFileDialog1 As New OpenFileDialog()

                    openFileDialog1.Title = "File " & "2_333333"
                    openFileDialog1.InitialDirectory = "C:\"
                    openFileDialog1.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*|" & ".Test" & "|*" & ".Test"
                    openFileDialog1.FilterIndex = 2
                    openFileDialog1.RestoreDirectory = True


                    openFileDialog1.ShowDialog() 'here the error is generated

                    If openFileDialog1.ShowDialog() = DialogResult.OK Then
                        Try
                            myStream = openFileDialog1.OpenFile()
                            If (myStream IsNot Nothing) Then
                                myStream.Close()
                                MsgBox(openFileDialog1.FileName)
                            End If
                        Catch Ex As Exception
                            MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
                        Finally
                            If (myStream IsNot Nothing) Then
                                myStream.Close()
                            End If
                        End Try
                    End If
                End If
            End If

            Thread.Sleep(100)
        Next

Another thing : if I use modal wait, is not possible to debug in case of error or exception, is it correct ?
That makes no sense at all. Like I said, the whole point of this is to give the user something to look at while the application is doing work in the background and they can't use the UI. If you expect them select a file using a dialogue then that is the very definition of using the UI so why are you even trying to use this dialogue or do anything in the background? There's no reason for you to be using this dialogue so don't. That is the last I will say on the matter.