
Originally Posted by
jmcilhinney
If it didn't work then you did it wrong. I don't know what you did so I have no idea what you did wrong. Did someone tell you I was psychic?
That said, why would you try it with an OpenFileDialog in the first place? The whole point of this is to give the user something to look at and provide feedback while work is performed in the background. How exactly is an OpenFileDialog background work?
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 ?