Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
Dim DestFile As String = "c:\temp\"
If Not IO.Directory.Exists(DestFile) Then
IO.Directory.CreateDirectory(DestFile)
End If
Dim objApp As New PowerPointMe.Application
objApp.Visible = MsoTriState.msoTrue
objApp.Presentations.Open(FileStr, MsoTriState.msoFalse, MsoTriState.msoCTrue, MsoTriState.msoCTrue)
objApp.Assistant.On = False
objApp.Presentations(1).SaveAs(DestFile & "Benefit_" & BenefitID & ".bmp", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsBMP, MsoTriState.msoCTrue)
Dim PresentationByte() As Byte = Nothing
Dim FileArray(objApp.Presentations(1).Slides.Count - 1) As Object
Dim i As Integer = 1
For i = 1 To objApp.Presentations(1).Slides.Count
Dim SlideFileStr As String = DestFile & "Benefit_" & BenefitID & "\Slide" & i & ".bmp"
Dim FS As IO.FileStream = IO.File.Open(SlideFileStr, IO.FileMode.Open)
ReDim PresentationByte(FS.Length - 1)
FS.Read(PresentationByte, 0, FS.Length - 1)
FS.Close()
'Save File into array, the array will be saved to the db and pulled back out on the client
FileArray(i - 1) = PresentationByte
Next
Try
objApp.ActiveWindow.Close()
Catch
End Try
Try
If objApp.Presentations.Count > 0 Then
objApp.Presentations(1).Close()
End If
Catch ex As Exception
If Debugger.IsAttached Then Stop
End Try
Try
objApp.Quit()
Catch ex As Exception
If Debugger.IsAttached Then Stop
End Try
GC.Collect()
Return ConvertObjectToBytes(FileArray)
ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x1bc5bbd0 to COM context 0x1bc5be20 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Join the community of 500,000 technology professionals and ask your questions.