Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5973291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:46:47+00:00 2026-05-22T20:46:47+00:00

I have a VB.NET user control that is saving a PDF document and then

  • 0

I have a VB.NET user control that is saving a PDF document and then displaying that in a WebBrowser control. The code looks like this:

Using myPdfDoc As New FileStream(fileName, FileMode.Create)
    Dim byt As Byte() = comLib.GetData();
    If Not byt Is Nothing Then                        
        myPdfDoc.Write(byt, 0, byt.Length)
        myPdfDoc.Flush()
        myPdfDoc.Close()

        webBrowserCtl.Navigate(fileName)
    End If
End Using

comLib is a COM interop library, written in VB6 that obtains the relevant data.

As far as I can tell, this code is keeping a reference to the PDF document (as VB.NET does not close when the program finishes). I found this article which seems to imply that adobe doesn’t clean up after itself properly, but implementing its suggested changes doesn’t seem to help.

Why might I be getting this behaviour? In VB6, a program not closing properly was always a result of stray object references that are not cleared up. Is this still true in VB.NET? If so, what can I do to identify which object, or why this might be happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:46:47+00:00Added an answer on May 22, 2026 at 8:46 pm

    I would separate this out: reading the data, writing the data, and viewing the data:

    Dim byt As Byte() = Nothing
    Try
      byt = comLib.GetData()
    Finally
      If Not comLib Is Nothing Then
        Marshal.ReleaseComObject(comLib)
      End If
    End Try
    
    If Not byt Is Nothing Then
      Using myPdfDoc As New FileStream(fileName, FileMode.Create)
        myPdfDoc.Write(byt, 0, byt.Length)
      End Using
    
      Using webBrowserCtl As New WebBrowser()
        webBrowserCtl.Navigate(fileName)      
      End Using
    End If  
    

    The Marshal.ReleaseComObject call in the Finally ensures that the reference count is always decremented. The Flush and Close are not necessary, as Dispose will do this anyway. The WebBrowser control implements IDisposable, so I have used a Using block for that too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple ASP.NET Web User Control. It looks like this: <%@ Control
I have a very simplistic user control that looks like this: <%@ Control Language=C#
I have an ASP.NET user control that contains a text box control and a
I have an ASP.Net web user control that contains a TextBox and a calendar
I have an ASP.NET user control (.ascx file). In this user control I want
I have an ASP.NET user control that is used in another use control. The
I have a custom ASP.NET user control that is added to a panel on
I have an ASP.NET Page that contains a User control called ReportCtrl (my own
I have an ASP.Net user control that contains some checkboxes, and I want to
I have an ASP.NET user control that references some CSS classes. In the Error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.