관찰 가능한 시퀀스의 각 요소를 타이밍 정보를 기반으로 생성되는 0개 이상의 창으로 프로젝스합니다.
네임스페이스:System.Reactive.Linq
어셈블리: System.Reactive(System.Reactive.dll)
Syntax
'Declaration
<ExtensionAttribute> _
Public Shared Function Window(Of TSource) ( _
source As IObservable(Of TSource), _
timeSpan As TimeSpan, _
timeShift As TimeSpan, _
scheduler As IScheduler _
) As IObservable(Of IObservable(Of TSource))
'Usage
Dim source As IObservable(Of TSource)
Dim timeSpan As TimeSpan
Dim timeShift As TimeSpan
Dim scheduler As IScheduler
Dim returnValue As IObservable(Of IObservable(Of TSource))
returnValue = source.Window(timeSpan, _
timeShift, scheduler)
public static IObservable<IObservable<TSource>> Window<TSource>(
this IObservable<TSource> source,
TimeSpan timeSpan,
TimeSpan timeShift,
IScheduler scheduler
)
[ExtensionAttribute]
public:
generic<typename TSource>
static IObservable<IObservable<TSource>^>^ Window(
IObservable<TSource>^ source,
TimeSpan timeSpan,
TimeSpan timeShift,
IScheduler^ scheduler
)
static member Window :
source:IObservable<'TSource> *
timeSpan:TimeSpan *
timeShift:TimeSpan *
scheduler:IScheduler -> IObservable<IObservable<'TSource>>
JScript does not support generic types and methods.
형식 매개 변수
- TSource
원본의 형식입니다.
매개 변수
- source
형식: System.IObservable<TSource>
창을 생성할 원본 시퀀스입니다.
- timeSpan
형식: System.TimeSpan
각 창의 길이입니다.
- timeShift
형식: System.TimeSpan
연속 창을 만드는 간격입니다.
- scheduler
형식: System.Reactive.Concurrency.IScheduler
창 타이머를 실행할 스케줄러입니다.
반환 값
형식: System.IObservable<IObservable<TSource>>
관찰 가능한 창 시퀀스입니다.
사용 정보
Visual Basic 및 C#에서는 IObservable TSource> 형식의 모든 개체에서 이 메서드를 instance 메서드로 호출할 수 있습니다<. 인스턴스 메서드 구문을 사용하여 이 메서드를 호출할 경우에는 첫 번째 매개 변수를 생략합니다. 자세한 내용은 또는 를 참조하세요.
설명
Window 연산자는 원본 시퀀스를 시퀀스의 창 보기와 같은 버퍼링된 하위 집합으로 나눕니다. timeSpan 매개 변수는 해당 기간 동안 창을 열어 두어 각 창 버퍼에 배치되는 항목 수를 제어합니다. timeShift 매개 변수는 이전 창의 시작 부분에서 새 창이 열리기 전에 완료되어야 하는 시간 범위를 나타냅니다. 이렇게 하면 해당 시간 범위의 기간에 따라 보기가 시퀀스로 이동합니다. 스케줄러 매개 변수는 timeSpan 및 timeShift 매개 변수와 연결된 타이머를 실행할 위치를 제어합니다.
예제
이 예제에서는 Window 연산자를 사용하여 Interval 연산자의 정수 시퀀스를 1초마다 관찰합니다. 각 정수 시퀀스는 창을 통해 볼 수 있습니다. 각 창은 2.5초 동안 열린 다음 닫힙니다. timeShift 매개 변수는 5초로 설정됩니다. 즉, 이전 창이 열린 시간부터 5초마다 새 창이 열립니다. 최종 결과는 창을 2.5초 동안 연 다음 2.5초 동안 닫습니다. 따라서 시퀀스에는 0부터 시작하여 5번째 정수마다 시작하는 두 개의 정수가 포함됩니다.
using System;
using System.Reactive.Linq;
using System.Reactive.Concurrency;
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 timeSpan parameter controls how many items are placed in each window buffer by ***//
//*** keeping the window open for the duration of the time span. ***//
//*** ***//
//*** The timeShift parameter indicates the time span which must complete before a new ***//
//*** window opens. This shifts the view into the sequence based on the duration of the time ***//
//*** span. ***//
//*** ***//
//*** The ThreadPool scheduler is used to run the timers on a .NET thread pool thread. This ***//
//*** prevents the main thread from being blocked so pressing enter can exit the example. ***//
//*** ***//
//*** In this example each window will be open for 2.5 seconds. This will allow each window ***//
//*** to hold some items from the sequence starting with the first item (0). Then the ***//
//*** timeShift parameter shifts the next window opening by 5 seconds from the beginning of ***//
//*** the previous window. The result is that a window is open for 2.5 seconds then closed ***//
//*** for 2.5 seconds. ***//
//**********************************************************************************************//
var mainSequence = Observable.Interval(TimeSpan.FromSeconds(1));
TimeSpan timeSpan = TimeSpan.FromSeconds(2.5);
TimeSpan timeShift = TimeSpan.FromSeconds(5);
var seqWindowed = mainSequence.Window(timeSpan, timeShift, Scheduler.ThreadPool);
//*********************************************************************************************//
//*** A subscription to seqWindowed will provide a new IObservable<long> for some items in ***//
//*** the main sequence starting with the first item. Then we will receive a new observable ***//
//*** for every window. ***//
//*** ***//
//*** Create a subscription to each window into the main sequence and list the values. ***//
//*********************************************************************************************//
Console.WriteLine("Creating the subscription. Press ENTER to exit...\n");
seqWindowed.Subscribe(seqWindow =>
{
Console.WriteLine("\nA new window into the main sequence has been opened\n");
seqWindow.Subscribe(x =>
{
Console.WriteLine("Integer : {0}", x);
});
});
Console.ReadLine();
}
}
}
다음 출력은 예제 코드에 의해 생성되었습니다.
Creating the subscription. Press ENTER to exit...
A new window into the main sequence has been opened
Integer : 0
Integer : 1
A new window into the main sequence has been opened
Integer : 5
Integer : 6
A new window into the main sequence has been opened
Integer : 10
Integer : 11
A new window into the main sequence has been opened
Integer : 15
Integer : 16
A new window into the main sequence has been opened
Integer : 20
Integer : 21