/// <summary>
        /// Registers a form for receiving a callback notification when another instance was started. This typically should be the main form.
        /// </summary>
        /// <param name="form">The form to register.</param>
        public void RegisterForm(Form form)
        {
            if (IsAnotherInstanceRunning)
            {
                throw new InvalidOperationException("The application can't listen for notifications, as it is not the first instance.");
            }

            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }
            if (_forms.Contains(form))
            {
                throw new ArgumentException("The specified form is already registered.", nameof(form));
            }

            // Create filter if needed.
            if (_messageFilter == null)
            {
                _messageFilter = new CopyDataMessageFilter(this);
            }

            // If we are not currently listening, assign this form.
            if (_messageFilter.Handle == IntPtr.Zero)
            {
                _messageFilter.AssignHandle(form.Handle);
            }

            // Keep a list of all registered forms.
            form.Disposed += Form_Disposed;
            _forms.Add(form);
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing">True if disposing.</param>
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _messageFilter?.ReleaseHandle();
                _messageFilter = null;
            }

            if (_mutexOwned)
            {
                _mutex.ReleaseMutex();
            }
            _mutex.Dispose();

            _disposed = true;
        }
		/// <summary>
		/// Registers a form for receiving a callback notification when another instance was started. This typically should be the main form.
		/// </summary>
		/// <param name="form">The form to register.</param>
		public void RegisterForm(Form form)
		{
			if (IsAnotherInstanceRunning)
				throw new InvalidOperationException("The application can't listen for notifications, as it is not the first instance.");

			if (form == null)
				throw new ArgumentNullException(nameof(form));
			if (_forms.Contains(form))
				throw new ArgumentException("The specified form is already registered.", nameof(form));

			// Create filter if needed.
			if (_messageFilter == null)
				_messageFilter = new CopyDataMessageFilter(this);

			// If we are not currently listening, assign this form.
			if (_messageFilter.Handle == IntPtr.Zero)
				_messageFilter.AssignHandle(form.Handle);

			// Keep a list of all registered forms.
			form.Disposed += Form_Disposed;
			_forms.Add(form);
		}
		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
		/// </summary>
		/// <param name="disposing">True if disposing.</param>
		private void Dispose(bool disposing)
		{
			if (_disposed) return;

			if (disposing)
			{
				_messageFilter?.ReleaseHandle();
				_messageFilter = null;
			}

			if (_mutexOwned) _mutex.ReleaseMutex();
			_mutex.Dispose();

			_disposed = true;
		}