Unloading a DLL to update it.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ECathell

    Unloading a DLL to update it.

    I have done some searches on this and have found Herfrieds suggestions on opening the DLL in a different appDomain. I have not done this before and am curious on the consequences. Below is the code I am currently using, but it locks the dll.

    <STAThread()> _
    Public Shared Sub Main()
    Try
    Dim t As New Thread(AddressO f StartApplicatio n)
    t.Name = "DLLThread"
    t.Start()
    If CheckforUpdates () = True Then
    ' Prompt user if he wants to apply the updates
    If MessageBox.Show ("Updates are available for this program. Do you wish to install the updates?", "Updates Available", MessageBoxButto ns.YesNo, MessageBoxIcon. Information) = DialogResult.Ye s Then
    t.Abort()
    t = Nothing

    UpdateApplicati on()
    StartApplicatio n()

    End If

    End If

    Catch ex As Exception
    MessageBox.Show (ex.ToString, "Exception Thrown")
    Finally

    End Try
    End Sub


    Private Shared Sub StartApplicatio n()
    Dim frm As New TestingForm.For m1
    Application.Run (frm)

    End Sub

    --
    --Eric Cathell, MCSA
  • kurtcobain1978

    #2
    RE: Unloading a DLL to update it.

    Eric,

    pardon me but I'm not very clear on few things:

    - Is your application loading/using this DLL as well or does it just
    update/copy it?
    - If your application is actually loading it, are you doing a dynamic load?

    When you say it locks the dll, does that mean that you are not able to
    update it? The reason i would understand is that you are not doing a clean
    unload. If your application is loading the DLL, then use dynamic loading and
    do a clean unload. i am doing an update (based on a windows event) it myself
    in my Vb.net sample and didn't have any issues.

    I can post some code on how do to that but I'm not really sure what I am
    saying is relevant. Lemme know.

    Regards,
    Danny


    "ECathell" wrote:
    [color=blue]
    > I have done some searches on this and have found Herfrieds suggestions on opening the DLL in a different appDomain. I have not done this before and am curious on the consequences. Below is the code I am currently using, but it locks the dll.
    >
    > <STAThread()> _
    > Public Shared Sub Main()
    > Try
    > Dim t As New Thread(AddressO f StartApplicatio n)
    > t.Name = "DLLThread"
    > t.Start()
    > If CheckforUpdates () = True Then
    > ' Prompt user if he wants to apply the updates
    > If MessageBox.Show ("Updates are available for this program. Do you wish to install the updates?", "Updates Available", MessageBoxButto ns.YesNo, MessageBoxIcon. Information) = DialogResult.Ye s Then
    > t.Abort()
    > t = Nothing
    >
    > UpdateApplicati on()
    > StartApplicatio n()
    >
    > End If
    >
    > End If
    >
    > Catch ex As Exception
    > MessageBox.Show (ex.ToString, "Exception Thrown")
    > Finally
    >
    > End Try
    > End Sub
    >
    >
    > Private Shared Sub StartApplicatio n()
    > Dim frm As New TestingForm.For m1
    > Application.Run (frm)
    >
    > End Sub
    >
    > --
    > --Eric Cathell, MCSA[/color]

    Comment

    • Chris Dunaway

      #3
      Re: Unloading a DLL to update it.

      What does the CheckForUpdates method do?

      Comment

      • ECathell

        #4
        Re: Unloading a DLL to update it.

        While it is not relevant to the post and the question here is the code in
        the checkforupdates

        Private Shared Function CheckforUpdates () As Boolean

        ' Try
        ' ' Get the updater manager
        ' Dim updater As ApplicationUpda terManager =
        ApplicationUpda terManager.GetU pdater()

        ' Dim manifests As Manifest() = Nothing
        ' manifests = updater.CheckFo rUpdates()
        ' If manifests.Lengt h > 0 Then
        ' Return True
        ' Else
        ' Return False
        ' End If
        ' Catch ex As ThreadAbortExce ption
        ' ' Do nothing if the thread is being aborted, as we are explicitly
        doing it
        ' Catch ex As Exception
        ' MessageBox.Show (ex.ToString, "Error", MessageBoxButto ns.OK,
        MessageBoxIcon. Error)
        ' End Try

        ' End Function 'CheckAndUpdate

        --
        --Eric Cathell, MCSA
        "Chris Dunaway" <dunawayc@gmail .com> wrote in message
        news:1126124145 .750010.154080@ g49g2000cwa.goo glegroups.com.. .[color=blue]
        > What does the CheckForUpdates method do?
        >[/color]


        Comment

        • ECathell

          #5
          Re: Unloading a DLL to update it.

          Currently what I am doing is starting my application on a different thread,
          checking for updates on the main thread, if there are updates then the
          thread is stopped and the update is completed on the main thread. The
          application is then restarted on the main thread. Since I am loading the dll
          (which is actually the MDI interface for the application) it is locked from
          being used. On more investigation yesterday, i found that even when it is no
          longer used and disposed(t=noth ing) it is still locked for use by the
          windows application.

          Looking over the other quickstarts I think I am going to try modifying the
          No-Touch Deployment Quickstart,I think it has exactly what I am trying to do
          in it...

          --
          --Eric Cathell, MCSA
          "kurtcobain1978 " <kurtcobain1978 @discussions.mi crosoft.com> wrote in message
          news:7F1D503E-9A79-4323-9AB1-6A1BA07D24D0@mi crosoft.com...[color=blue]
          > Eric,
          >
          > pardon me but I'm not very clear on few things:
          >
          > - Is your application loading/using this DLL as well or does it just
          > update/copy it?
          > - If your application is actually loading it, are you doing a dynamic
          > load?
          >
          > When you say it locks the dll, does that mean that you are not able to
          > update it? The reason i would understand is that you are not doing a clean
          > unload. If your application is loading the DLL, then use dynamic loading
          > and
          > do a clean unload. i am doing an update (based on a windows event) it
          > myself
          > in my Vb.net sample and didn't have any issues.
          >
          > I can post some code on how do to that but I'm not really sure what I am
          > saying is relevant. Lemme know.
          >
          > Regards,
          > Danny
          >
          >
          > "ECathell" wrote:
          >[color=green]
          >> I have done some searches on this and have found Herfrieds suggestions on
          >> opening the DLL in a different appDomain. I have not done this before and
          >> am curious on the consequences. Below is the code I am currently using,
          >> but it locks the dll.
          >>
          >> <STAThread()> _
          >> Public Shared Sub Main()
          >> Try
          >> Dim t As New Thread(AddressO f StartApplicatio n)
          >> t.Name = "DLLThread"
          >> t.Start()
          >> If CheckforUpdates () = True Then
          >> ' Prompt user if he wants to apply the updates
          >> If MessageBox.Show ("Updates are available for this program. Do
          >> you wish to install the updates?", "Updates Available",
          >> MessageBoxButto ns.YesNo, MessageBoxIcon. Information) = DialogResult.Ye s
          >> Then
          >> t.Abort()
          >> t = Nothing
          >>
          >> UpdateApplicati on()
          >> StartApplicatio n()
          >>
          >> End If
          >>
          >> End If
          >>
          >> Catch ex As Exception
          >> MessageBox.Show (ex.ToString, "Exception Thrown")
          >> Finally
          >>
          >> End Try
          >> End Sub
          >>
          >>
          >> Private Shared Sub StartApplicatio n()
          >> Dim frm As New TestingForm.For m1
          >> Application.Run (frm)
          >>
          >> End Sub
          >>
          >> --
          >> --Eric Cathell, MCSA[/color][/color]


          Comment

          • Chris Dunaway

            #6
            Re: Unloading a DLL to update it.

            I only asked because the code you posted does not seem to use an
            AppDomain anywhere. I was wondering how you know if you need to
            update? Do you load the assembly and check its version? Do you go by
            the file date/time?

            If you load the assembly to check it's version, then there is no way to
            unload it unless you load it in a different AppDomain and I was
            wondering if your CheckForUpdates method loaded the assembly in a
            different AppDomain. Once the assembly is loaded, I think it will be
            locked and that is blocking your attempt to update it.

            Comment

            Working...