Unloading a DLL to update it.

E

ECathell

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(AddressOf StartApplication)
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", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes Then
t.Abort()
t = Nothing

UpdateApplication()
StartApplication()

End If

End If

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

End Try
End Sub


Private Shared Sub StartApplication()
Dim frm As New TestingForm.Form1
Application.Run(frm)

End Sub
 
G

Guest

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
 
E

ECathell

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 ApplicationUpdaterManager =
ApplicationUpdaterManager.GetUpdater()

' Dim manifests As Manifest() = Nothing
' manifests = updater.CheckForUpdates()
' If manifests.Length > 0 Then
' Return True
' Else
' Return False
' End If
' Catch ex As ThreadAbortException
' ' Do nothing if the thread is being aborted, as we are explicitly
doing it
' Catch ex As Exception
' MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
' End Try

' End Function 'CheckAndUpdate
 
E

ECathell

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=nothing) 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...
 
C

Chris Dunaway

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top