StreamedFileDataRequestedHandler 대리자

정의

해당 파일에 처음 액세스할 때 StorageFile 으로 데이터를 스트리밍하는 메서드를 나타냅니다.

public delegate void StreamedFileDataRequestedHandler(StreamedFileDataRequest ^ stream);
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.Guid(4277577764, 12257, 19719, 163, 91, 183, 124, 80, 181, 244, 204)]
class StreamedFileDataRequestedHandler : MulticastDelegate
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.Guid(4277577764, 12257, 19719, 163, 91, 183, 124, 80, 181, 244, 204)]
public delegate void StreamedFileDataRequestedHandler(StreamedFileDataRequest stream);
var streamedFileDataRequestedHandlerHandler = function(stream){
/* Your code */
}
Public Delegate Sub StreamedFileDataRequestedHandler(stream As StreamedFileDataRequest)

매개 변수

stream
StreamedFileDataRequest

CreateStreamedFileAsync 또는 ReplaceWithStreamedFileAsync 메서드에서 만든 StorageFile의 스트리밍된 데이터에 대한 요청입니다.

특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

다음 간단한 예제에서는 StreamedFileDataRequestedHandler 대리자의 instance 만드는 방법을 보여 줍니다. 또한 이 instance 파일에 처음 액세스할 때 CreateStreamedFileAsync에서 반환된 StorageFile에 대한 데이터 스트림을 생성하는 방법도 보여 줍니다.

이 간단한 예제는 StreamedFileDataRequestedHandler 대리자를 사용하기 위한 프로그래밍 패턴을 보여주기 위한 것입니다. 생성하기 쉬운 데이터가 있는 작은 파일의 경우 스트리밍 패턴이 유용하지 않습니다.

using Windows.Storage;
using Windows.Storage.Streams;

private async void CreateStreamedFile()
{
    // Create a streamed file.
    StorageFile file =
    await StorageFile.CreateStreamedFileAsync("file.txt",
        StreamedFileWriter, null);

    // Prepare to copy the file.
    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
    string newName = "copied_file.txt";

    // Copy the streamed file. At this point,
    // the data is streamed into the source file.
    await file.CopyAsync(localFolder, newName,
        NameCollisionOption.ReplaceExisting);
}

private async void StreamedFileWriter(StreamedFileDataRequest request)
{
    try
    {
        using (var stream = request.AsStreamForWrite())
        using (var streamWriter = new StreamWriter(stream))
        {
            for (int l = 0; l < 50; l++)
            {
                await streamWriter.WriteLineAsync("Data.");
            }
        }
        request.Dispose();
    }
    catch (Exception ex)
    {
        request.FailAndClose(StreamedFileFailureMode.Incomplete);
    }
}

설명

만드는 대리자의 instance CreateStreamedFileAsync 또는 ReplaceWithStreamedFileAsync 메서드에서 반환된 StorageFile에 대한 데이터 스트림을 생성합니다.

CreateStreamedFileAsync 또는 ReplaceWithStreamedFileAsync 메서드를 StreamedFileDataRequestedHandler의 instance 함께 사용하는 경우 파일을 만들 때 파일 내용을 작성하는 대신 요청 시 파일에 대한 데이터를 제공할 수 있습니다. 즉, 파일에 처음 액세스할 때까지 파일의 데이터를 생성하기 위해 비용이 많이 드는 작업을 연기할 수 있습니다.

적용 대상