// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.Reactive.Concurrency;
using System.Windows.Forms;
namespace System.Reactive.Linq
{
///
/// Provides a set of static methods for subscribing to IObservables using Windows Forms controls.
///
public static class ControlObservable
{
///
/// Wraps the source sequence in order to run its subscription and unsubscription logic on the Windows Forms message loop associated with the specified control.
///
/// The type of the elements in the source sequence.
/// Source sequence.
/// Windows Forms control whose associated message loop is used to to perform subscription and unsubscription actions on.
/// The source sequence whose subscriptions and unsubscriptions happen on the Windows Forms message loop associated with the specified control.
/// or is null.
///
/// Only the side-effects of subscribing to the source sequence and disposing subscriptions to the source sequence are run on the specified control.
/// In order to invoke observer callbacks on the specified control, e.g. to render results in a control, use .
///
public static IObservable SubscribeOn(this IObservable source, Control control)
{
if (source == null)
throw new ArgumentNullException("source");
if (control == null)
throw new ArgumentNullException("control");
return Synchronization.SubscribeOn(source, new ControlScheduler(control));
}
///
/// Wraps the source sequence in order to run its observer callbacks on the Windows Forms message loop associated with the specified control.
///
/// The type of the elements in the source sequence.
/// Source sequence.
/// Windows Forms control whose associated message loop is used to to notify observers on.
/// The source sequence whose observations happen on the Windows Forms message loop associated with the specified control.
/// or is null.
public static IObservable ObserveOn(this IObservable source, Control control)
{
if (source == null)
throw new ArgumentNullException("source");
if (control == null)
throw new ArgumentNullException("control");
return Synchronization.ObserveOn(source, new ControlScheduler(control));
}
}
}