title: How to update dll-file without main program being restart?
body: <p>How to update dll-file without program being restart?</p>
  
  <p>I want to create my "Updater" class. It's main idea is to
       check local(connected to executive file) and server dll-files, 
       and when newer version is available, copying server file to local.</p>
  
  <p><strong>Code:</strong> </p>
  
  <pre><code>Updater updater = new Updater(LOCAL_PATH, SERVER_PATH);
  if (updater.IsAvailableNewerVersion)
      updater.Update();
  </code></pre>
  
  <p>Updater's ctor take two paths - to server dll and to local dll and calculate their Versions.
       Then I call a property IsAvailableNewerVersion - if it's true (available version is newer then a local), I call Update method.
       Main Idea of Update method is to copying server dll-file to local with overwrite, and say to user to restart program.</p>
  
  <p><strong>Code:</strong> </p>
  
  <pre><code>public class Updater
  {
      private readonly string _localPath;
      private readonly string _serverPath;
      private readonly Version _currentVersion;
      private readonly Version _availableVersion;
  
      public Updater(string localPath, string serverPath)
      {
          _localPath = localPath;
          _serverPath = serverPath;
          _currentVersion = AssemblyName.GetAssemblyName(_localPath).Version;
          _availableVersion = AssemblyName.GetAssemblyName(_serverPath).Version;
      }
      public bool IsAvailableNewerVersion =&gt; _availableVersion.Major &gt; _currentVersion.Major ||
                                             _availableVersion.MajorRevision &gt; _currentVersion.MajorRevision ||
                                             _availableVersion.Minor &gt; _currentVersion.Minor ||
                                             _availableVersion.MinorRevision &gt; _currentVersion.MinorRevision ||
                                             _availableVersion.Build &gt; _currentVersion.Build ||
                                             _availableVersion.Revision &gt; _currentVersion.Revision;
      public void Update()
      {
          try
          {
              File.Copy(_serverPath, _localPath, true);
          }
          catch (Exception e)
          {
              MessageBox.Show("Unable to copying file - " + e);
              return;
          }
          MessageBox.Show("File was successfully updated. Please restart program.");
      }
  }
  </code></pre>
  
  <ol>
  <li>Is there a way to check dll-files before they being used?</li>
  <li>How to update dll-file without program being restart?</li>
  </ol>
  
  <p><strong>P.S.</strong>
  I think to use server dll-files, but my program becomes dependent on the server that is not good.</p>