Code for using FileSystemWatcher class in VB.NET :
=========================================================
The following code should be written before the new values are saved to the config 'file.
First you have to declare an object for FileSystemWatcher class.
Example:
==========================================================
Public Shared fileWatcher As FileSystemWatcher
' pathString holds the path of config file.
Dim pathString As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
Dim filename As String = "SystemWatcher.exe.config"
fileWatcher = New FileSystemWatcher()
fileWatcher.Path = pathString
fileWatcher.Filter = filename
fileWatcher.NotifyFilter = (NotifyFilters.CreationTime Or NotifyFilters.LastWrite Or NotifyFilters.FileName)
AddHandler fileWatcher.Changed, New FileSystemEventHandler(AddressOf OnChange)
fileWatcher.EnableRaisingEvents = True
===========================================================
' On change event configuration file getting refreshed.
Private Shared Sub OnChange(ByVal sender As Object, ByVal e As FileSystemEventArgs)
ConfigurationManager.RefreshSection("AppSettings")
End Sub
==================================================================