다음을 통해 공유


Observable.Window<TSource, TWindowClosing> 메서드(IObservable<TSource>, Func<IObservable<TWindowClosing>>)

관찰 가능한 시퀀스의 각 요소를 연속된 겹치지 않는 창으로 투영합니다.

네임스페이스:System.Reactive.Linq
어셈블리: System.Reactive(System.Reactive.dll)

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Function Window(Of TSource, TWindowClosing) ( _
    source As IObservable(Of TSource), _
    windowClosingSelector As Func(Of IObservable(Of TWindowClosing)) _
) As IObservable(Of IObservable(Of TSource))
'Usage
Dim source As IObservable(Of TSource)
Dim windowClosingSelector As Func(Of IObservable(Of TWindowClosing))
Dim returnValue As IObservable(Of IObservable(Of TSource))

returnValue = source.Window(windowClosingSelector)
public static IObservable<IObservable<TSource>> Window<TSource, TWindowClosing>(
    this IObservable<TSource> source,
    Func<IObservable<TWindowClosing>> windowClosingSelector
)
[ExtensionAttribute]
public:
generic<typename TSource, typename TWindowClosing>
static IObservable<IObservable<TSource>^>^ Window(
    IObservable<TSource>^ source, 
    Func<IObservable<TWindowClosing>^>^ windowClosingSelector
)
static member Window : 
        source:IObservable<'TSource> * 
        windowClosingSelector:Func<IObservable<'TWindowClosing>> -> IObservable<IObservable<'TSource>> 
JScript does not support generic types and methods.

형식 매개 변수

  • TSource
    원본의 형식입니다.
  • TWindowClosing
    창 닫기의 형식입니다.

매개 변수

  • windowClosingSelector
    형식: System.Func<IObservable<TWindowClosing>>
    생성된 창의 경계를 정의하기 위해 호출된 함수입니다.

반환 값

형식: System.IObservable<IObservable<TSource>>
관찰 가능한 창 시퀀스입니다.

사용 정보

Visual Basic 및 C#에서는 IObservable TSource> 형식의 모든 개체에서 이 메서드를 instance 메서드로 호출할 수 있습니다<. 인스턴스 메서드 구문을 사용하여 이 메서드를 호출할 경우에는 첫 번째 매개 변수를 생략합니다. 자세한 내용은 또는 를 참조하세요.

설명

Window 연산자는 관찰 가능한 시퀀스를 연속된 겹치지 않는 창으로 구분합니다. 현재 창의 끝과 다음 창의 시작은 연산자에 입력 매개 변수로 전달되는 windowClosingSelect 함수의 결과인 관찰 가능한 시퀀스에 의해 제어됩니다. 연산자를 사용하여 이벤트 집합을 창으로 그룹화할 수 있습니다. 예를 들어 트랜잭션 상태는 관찰되는 기본 시퀀스일 수 있습니다. 이러한 상태에는 준비, 준비, 활성 및 커밋/중단이 포함될 수 있습니다. 기본 시퀀스에는 해당 순서대로 발생하는 모든 상태가 포함될 수 있습니다. windowClosingSelect 함수는 커밋됨 또는 중단 상태에서만 값을 생성하는 관찰 가능한 시퀀스를 반환할 수 있습니다. 그러면 특정 트랜잭션에 대한 트랜잭션 이벤트를 나타내는 창이 닫힙니다.

예제

다음 간단한 예제에서는 정수 시퀀스를 연속된 겹치지 않는 창으로 나눕니다. 현재 창의 끝과 다음 창의 시작은 Interval 연산자가 6초마다 생성하는 관찰 가능한 정수 시퀀스에 의해 제어됩니다. 기본 관찰 가능한 시퀀스가 1초마다 항목을 생성하므로 각 창에는 6개의 항목이 포함됩니다. 예제 코드는 6초마다 새 창이 열리는 것을 보여 주는 타임스탬프와 함께 정수의 각 창을 콘솔 창에 씁니다.

using System;
using System.Reactive.Linq;

namespace Example
{
  class Program
  {
    static void Main()
    {
      //*********************************************************************************************//
      //*** The mainSequence produces a new long integer from the Interval operator every sec but ***//
      //*** this sequence is broken up by the Window operator into subsets like a windowed        ***//
      //*** view of the sequence. The time when each window stops and the next window starts is   ***//
      //*** controlled by the IObservable<TWindowClosing> named seqWindowControl. It is returned  ***//
      //*** by the lambda expression which is passed to the Window operator. In this case it      ***//
      //**  returns another IObservable<long> generated by the Interval operator. So whenever     ***//
      //*** seqWindowControl produces a item, the current window into the mainSequence stops and  ***//
      //*** a new window starts.                                                                  ***//
      //*********************************************************************************************//

      var mainSequence = Observable.Interval(TimeSpan.FromSeconds(1));

      var seqWindowed = mainSequence.Window(() => 
      {
        var seqWindowControl = Observable.Interval(TimeSpan.FromSeconds(6));
        return seqWindowControl;
      });


      //*********************************************************************************************//
      //*** A subscription to seqWindowed will provide a new IObservable<long> every 6 secs.      ***//
      //***                                                                                       ***//
      //*** Create a subscription to each window into the main sequence and list the values along ***//
      //*** with the time the window was opened and the previous window was closed.               ***//
      //*********************************************************************************************//
      
      seqWindowed.Subscribe(seqWindow => 
      {
        Console.WriteLine("\nA new window into the main sequence has opened: {0}\n",DateTime.Now.ToString());
        seqWindow.Subscribe(x =>
        {
          Console.WriteLine("Integer : {0}", x);
        });
      });

      Console.ReadLine();
    }
  }
}

다음 출력은 예제 코드에 의해 생성되었습니다.

A new window into the main sequence has opened: 6/1/2011 8:48:43 PM

Integer : 0
Integer : 1
Integer : 2
Integer : 3
Integer : 4
Integer : 5

A new window into the main sequence has opened: 6/1/2011 8:48:49 PM

Integer : 6
Integer : 7
Integer : 8
Integer : 9
Integer : 10
Integer : 11

A new window into the main sequence has opened: 6/1/2011 8:48:55 PM

Integer : 12
Integer : 13
Integer : 14
Integer : 15
Integer : 16
Integer : 17

A new window into the main sequence has opened: 6/1/2011 8:49:02 PM

Integer : 18
Integer : 19
Integer : 20
Integer : 21
Integer : 22
Integer : 23

참고 항목

참조

관찰 가능한 클래스

창 오버로드

System.Reactive.Linq 네임스페이스