代码运行时显示一个对话框

时间:2015-03-13 19:21:09

标签: vb.net dialog

我有下面的代码打开一个对话框,其中包含进度给用户的消息,但问题是代码在等待结果时不会显示对话框。有没有办法解决这个问题?

    If VerifyDataInput() = True Then
        Dim dlg As New frmWorking
        dlg.lblMessage.Text = "Downloading Weather Data"
        dlg.ShowDialog()
        If GetWeather() = True Then
            dlg.lblMessage.Text = "Creating Weather Briefing"
            If CreateWeatherBriefing() = True Then
                Try
                    printWeatherBriefing.PrinterSettings = docWeatherBriefing.PrinterSettings
                    If printWeatherBriefing.ShowDialog() = Windows.Forms.DialogResult.OK Then
                        If printWeatherBriefing.PrinterSettings.PrinterName = strPrinterName Then
                            Dim strPrompt = "The selected printer is also your default RAW text printer." & Chr(10) & Chr(10) & _
                                            "Would you like to print a RAW text only version?"
                            Dim result = MessageBox.Show(strPrompt, Me.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3)

                            If result = Windows.Forms.DialogResult.Yes Then
                                Dim intExtraLines As Integer = 0
                                Do
                                    intExtraLines += 1
                                    strWXRawOutput &= Chr(10)
                                Loop Until intExtraLines = 6 + 1

                                RawPrinterHelper.SendStringToPrinter(strPrinterName, strWXRawOutput, szDocName)
                            ElseIf result = Windows.Forms.DialogResult.No Then
                                docWeatherBriefing.PrinterSettings = printWeatherBriefing.PrinterSettings
                                docWeatherBriefing.DocumentName = szDocName
                                docWeatherBriefing.Print()
                            End If
                        Else
                            docWeatherBriefing.PrinterSettings = printWeatherBriefing.PrinterSettings
                            docWeatherBriefing.DocumentName = szDocName
                            docWeatherBriefing.Print()
                        End If
                    End If
                Catch ex As Exception
                    Dim strPrompt = "An error occurred when trying to print your weather briefing, please try again."
                    Dim blnErrorLogged = WriteToErrorLog(ex.Message, ex.StackTrace.ToString, strPrompt, "Error")
                    MsgBox(strPrompt, MsgBoxStyle.Critical, Me.Text)
                Finally
                    dlg.Dispose()
                End Try
            End If
        End If
        dlg.Dispose()
    End If

0 个答案:

没有答案