/// <summary> /// Ensures that a client for this GrandOutput is registered on a monitor. /// </summary> /// <param name="monitor">The monitor onto which a <see cref="GrandOutputClient"/> must be registered.</param> /// <returns>A newly created client or the already existing one.</returns> public GrandOutputClient Register(IActivityMonitor monitor) { if (monitor == null) { throw new ArgumentNullException("monitor"); } AttemptGarbageDeadClients(); Func <GrandOutputClient> reg = () => { var c = new GrandOutputClient(this); lock (_clients) _clients.Add(new WeakReference <GrandOutputClient>(c)); return(c); }; return(monitor.Output.RegisterUniqueClient(b => b.Central == this, reg)); }
GrandOutputClient?DoEnsureGrandOutputClient(IActivityMonitor monitor) { GrandOutputClient?Register() { var c = new GrandOutputClient(this); lock ( _clients ) { if (IsDisposed) { c = null; } else { _clients.Add(new WeakReference <GrandOutputClient>(c)); } } return(c); } return(monitor.Output.RegisterUniqueClient(b => { Debug.Assert(b != null); return b.Central == this; }, Register)); }
/// <summary> /// Ensures that a client for this GrandOutput is registered on a monitor. /// </summary> /// <param name="monitor">The monitor onto which a <see cref="GrandOutputClient"/> must be registered.</param> /// <returns>A newly created client or the already existing one.</returns> public GrandOutputClient Register( IActivityMonitor monitor ) { if( monitor == null ) throw new ArgumentNullException( "monitor" ); AttemptGarbageDeadClients(); Func<GrandOutputClient> reg = () => { var c = new GrandOutputClient( this ); lock( _clients ) _clients.Add( new WeakReference<GrandOutputClient>( c ) ); return c; }; return monitor.Output.RegisterUniqueClient( b => b.Central == this, reg ); }