Private Sub ViewerDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Try
BackgroundWorker_Scan.RunWorkerAsync()
Dim dlgOpen As System.Windows.Forms.OpenFileDialog = New System.Windows.Forms.OpenFileDialog
If m_bAppendFromFile Then
dlgOpen.Filter = "PDF|*.PDF"
dlgOpen.FileName = "*.pdf"
dlgOpen.ShowDialog()
If dlgOpen.ShowDialog() <> DialogResult.OK Then Return
End If
If Not m_bAppendFromFile Then Return
' ********* Never gets past this while loop because the
' ********* background worker never finishes to set the
' ********* boolean to false.
While m_bWorkerRunning
Thread.Sleep(500)
End While
AxGdViewer1.DisplayFromPdfFile(dlgOpen.FileName)
Catch except As Exception
MsgBox(MethodBase.GetCurrentMethod.Name & " " & except.Message, vbCritical)
End Try
End Sub
Private Sub BackgroundWorker_Scan_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker_Scan.DoWork
Try
m_bWorkerRunning = True
Dim nAcquiredImage As Long
m_strPath = "\\Umisrv\EMR\EOB Images\" & m_strInsCode & "\"
m_strFile = m_datePosted.Year & "-" & m_datePosted.Month & "-" & m_datePosted.Day & " " & m_strCheckNumber & ".pdf"
If m_bAppend Then
AxGdViewer1.DisplayFromPdfFile(m_strPath & m_strFile)
AxGdViewer1.DisplayFirstFrame()
m_nTiffMultipage = AxImaging1.TiffCreateMultiPageFromGdPictureImage(AxGdViewer1.GetNativeImage)
Do
Debug.Write("1")
AxGdViewer1.DisplayNextFrame()
Debug.Write("2")
AxImaging1.TiffAppendPageFromGdPictureImage(m_nTiffMultipage, AxGdViewer1.GetNativeImage)
Debug.Write("3")
BackgroundWorker_Scan.ReportProgress(AxGdViewer1.CurrentPage)
Debug.Write("4")
Loop While AxGdViewer1.CurrentPage < AxGdViewer1.PageCount
Debug.WriteLine("5")
If Not m_bAppendFromFile Then
retry: delegateWaitTillLoaded()
If AxImaging1.TwainGetState < GdPicturePro5S.TwainStatus.TWAIN_SM_OPEN Then Return
If Not AxImaging1.TwainIsFeederLoaded Then GoTo retry
While AxImaging1.CreateImageFromTwain <> 0
nAcquiredImage = AxImaging1.GetNativeImage
AxImaging1.ConvertTo8BppQ()
AxImaging1.TiffAppendPageFromGdPictureImage(m_nTiffMultipage, nAcquiredImage)
AxGdViewer1.SetNativeImage(m_nTiffMultipage)
AxGdViewer1.DisplayLastFrame()
AxImaging1.CloseImage(nAcquiredImage)
BackgroundWorker_Scan.ReportProgress(0)
End While
AxGdViewer1.DisplayFirstFrame()
Do
AxGdViewer1.DisplayNextFrame()
Loop While AxGdViewer1.CurrentPage < AxGdViewer1.PageCount
End If
Else
Dim nPageCount As Long = AxGdViewer1.PageCount
Dim dirInfo As DirectoryInfo = New DirectoryInfo(m_strPath)
If Not dirInfo.Exists Then
CreateDirectory(m_strPath)
End If
retry2: delegateWaitTillLoaded()
If AxImaging1.TwainGetState < GdPicturePro5S.TwainStatus.TWAIN_SM_OPEN Then Return
If Not AxImaging1.TwainIsFeederLoaded Then GoTo retry2
While AxImaging1.CreateImageFromTwain <> 0
nPageCount += 1
AxImaging1.ConvertTo8BppQ()
nAcquiredImage = AxImaging1.GetNativeImage
If nPageCount = 1 Then
m_nTiffMultipage = AxImaging1.TiffCreateMultiPageFromGdPictureImage(nAcquiredImage)
Else
AxImaging1.TiffAppendPageFromGdPictureImage(m_nTiffMultipage, nAcquiredImage)
End If
AxGdViewer1.SetNativeImage(m_nTiffMultipage)
AxGdViewer1.DisplayLastFrame()
AxImaging1.CloseImage(nAcquiredImage)
BackgroundWorker_Scan.ReportProgress(nPageCount)
End While
End If
Catch except As Exception
m_bWorkerRunning = False
MsgBox(MethodBase.GetCurrentMethod.Name & " " & except.Message, vbCritical)
End Try
End Sub