hi,
I'm using a DotNet Application which uses several dlls.
Every time I create a new version and want to distribute it to the users, I have to remind the users to leave the application.
So I heard about shadow copying,
so that it might be possible to update certain dlls while the users are able to work and do not have to leave the application.
is there any coding example where your whole discription is coded ?
in my testclass I alwaxs get the message: file is used by other persons, could not be changed ...
it seems that the shadow copying mechanisms do not work regularly.
It would be very nice, if you could tell me, when to upload the assembly.
Do I have to upload the original assembly, how can I do this ?
Imports System.IO
Imports System.Reflection
Public Class Form1
Public Watcher As FileSystemWatcher
Private _DomainNumber As String = 1
Private _currentAssembly As System.Reflection.Assembly
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
LoadAppDomain()
InitWatcher()
Console.ReadLine()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub InitWatcher()
Try
Watcher = New System.IO.FileSystemWatcher()
' Monitoring-Pfad
Watcher.Path = "C:\Projekte\TestProjekte\ShadowCopying\ShadowCopy ing\bin\Debug\"
Watcher.Filter = "*.dll"
Watcher.IncludeSubdirectories = True
Watcher.EnableRaisingEvents = True
AddHandler Watcher.Changed, AddressOf OnAssemblyChange
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub LoadAppDomain()
Try
'Dim setup As New AppDomainSetup()
'setup.ApplicationBase = "Testdll\TB_DAL"
'setup.ShadowCopyDirectories = "C:\Temp;C:\Downloads"
'setup.ShadowCopyFiles = "true"
' Where do shadow copied bits go?
'AppDomainSetup.CachePath + AppDomainSetup.ApplicationName control where shadow copied bits go. If both CachePath and ApplicationName are set, shadow copied bits will go to CachePath\ApplicationName. Otherwise shadow copied bits will go to your download cache (which is stored in %userprofile%\local settings\application data\assembly). The combination of CachePath and ApplicationName is really handy for ASP.NET, because they can set a common CachePath, and have each application shadow copy to a different location.
'You are responsible to clean up the shadow copy cache if you set CachePath+ApplicationName. In the case of download cache as shadow copy cache, it is automatically managed by fusion.
Dim domain As AppDomain = AppDomain.CreateDomain("ShadowCopy domain " + _DomainNumber, Nothing, Nothing, Nothing, True)
_currentAssembly = domain.Load("TB_DAL", Nothing)
_DomainNumber = _DomainNumber + 1
AppDomain.Unload(domain)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub OnAssemblyChange(ByVal From As Object, ByVal e As FileSystemEventArgs)
' Zweck: Reagiert auf dll-Änderungen im Monitoring-Verzeichnis des Watchers und ruft "LoadAppDomain()" auf
Try
LoadAppDomain()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
I'm using a DotNet Application which uses several dlls.
Every time I create a new version and want to distribute it to the users, I have to remind the users to leave the application.
So I heard about shadow copying,
so that it might be possible to update certain dlls while the users are able to work and do not have to leave the application.
is there any coding example where your whole discription is coded ?
in my testclass I alwaxs get the message: file is used by other persons, could not be changed ...
it seems that the shadow copying mechanisms do not work regularly.
It would be very nice, if you could tell me, when to upload the assembly.
Do I have to upload the original assembly, how can I do this ?
Imports System.IO
Imports System.Reflection
Public Class Form1
Public Watcher As FileSystemWatcher
Private _DomainNumber As String = 1
Private _currentAssembly As System.Reflection.Assembly
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
LoadAppDomain()
InitWatcher()
Console.ReadLine()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub InitWatcher()
Try
Watcher = New System.IO.FileSystemWatcher()
' Monitoring-Pfad
Watcher.Path = "C:\Projekte\TestProjekte\ShadowCopying\ShadowCopy ing\bin\Debug\"
Watcher.Filter = "*.dll"
Watcher.IncludeSubdirectories = True
Watcher.EnableRaisingEvents = True
AddHandler Watcher.Changed, AddressOf OnAssemblyChange
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub LoadAppDomain()
Try
'Dim setup As New AppDomainSetup()
'setup.ApplicationBase = "Testdll\TB_DAL"
'setup.ShadowCopyDirectories = "C:\Temp;C:\Downloads"
'setup.ShadowCopyFiles = "true"
' Where do shadow copied bits go?
'AppDomainSetup.CachePath + AppDomainSetup.ApplicationName control where shadow copied bits go. If both CachePath and ApplicationName are set, shadow copied bits will go to CachePath\ApplicationName. Otherwise shadow copied bits will go to your download cache (which is stored in %userprofile%\local settings\application data\assembly). The combination of CachePath and ApplicationName is really handy for ASP.NET, because they can set a common CachePath, and have each application shadow copy to a different location.
'You are responsible to clean up the shadow copy cache if you set CachePath+ApplicationName. In the case of download cache as shadow copy cache, it is automatically managed by fusion.
Dim domain As AppDomain = AppDomain.CreateDomain("ShadowCopy domain " + _DomainNumber, Nothing, Nothing, Nothing, True)
_currentAssembly = domain.Load("TB_DAL", Nothing)
_DomainNumber = _DomainNumber + 1
AppDomain.Unload(domain)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub OnAssemblyChange(ByVal From As Object, ByVal e As FileSystemEventArgs)
' Zweck: Reagiert auf dll-Änderungen im Monitoring-Verzeichnis des Watchers und ruft "LoadAppDomain()" auf
Try
LoadAppDomain()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Comment