FileStream.EndWrite 方法
结束异步写入,在 I/O 操作完成之前一直阻止。
**命名空间:**System.IO
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public Overrides Sub EndWrite ( _
asyncResult As IAsyncResult _
)
用法
Dim instance As FileStream
Dim asyncResult As IAsyncResult
instance.EndWrite(asyncResult)
public override void EndWrite (
IAsyncResult asyncResult
)
public:
virtual void EndWrite (
IAsyncResult^ asyncResult
) override
public void EndWrite (
IAsyncResult asyncResult
)
public override function EndWrite (
asyncResult : IAsyncResult
)
参数
- asyncResult
挂起的异步 I/O 请求。
异常
异常类型 | 条件 |
---|---|
asyncResult 为 空引用(在 Visual Basic 中为 Nothing)。 |
|
此 IAsyncResult 对象不是通过对该类调用 BeginWrite 来创建的。 |
|
EndWrite 被多次调用。 |
备注
此方法重写 EndWrite。
对于 BeginWrite 中的每个 IAsyncResult,必须正好调用一次 EndWrite。EndWrite 将一直阻止到完成 I/O 操作为止。
下表列出了其他典型或相关的 I/O 任务的示例。
若要执行此操作... |
请参见本主题中的示例... |
---|---|
创建文本文件。 |
|
写入文本文件。 |
|
读取文本文件。 |
|
向文件中追加文本。 |
|
重命名或移动文件。 |
|
复制文件。 |
|
获取文件大小。 |
|
获取文件属性。 |
|
设置文件属性。 |
|
确定文件是否存在。 |
|
读取二进制文件。 |
|
写入二进制文件。 |
|
创建目录。 |
Directory.CreateDirectory |
示例
此代码示例是为 FileStream(String,FileMode,FileAccess,FileShare,Int32,Boolean) 构造函数提供的一个更大示例的一部分。
Private Shared Sub EndWriteCallback(asyncResult As IAsyncResult)
Dim tempState As State = _
DirectCast(asyncResult.AsyncState, State)
Dim fStream As FileStream = tempState.FStream
fStream.EndWrite(asyncResult)
' Asynchronously read back the written data.
fStream.Position = 0
asyncResult = fStream.BeginRead( _
tempState.ReadArray, 0 , tempState.ReadArray.Length, _
AddressOf EndReadCallback, tempState)
' Concurrently do other work, such as
' logging the write operation.
End Sub
static void EndWriteCallback(IAsyncResult asyncResult)
{
State tempState = (State)asyncResult.AsyncState;
FileStream fStream = tempState.FStream;
fStream.EndWrite(asyncResult);
// Asynchronously read back the written data.
fStream.Position = 0;
asyncResult = fStream.BeginRead(
tempState.ReadArray, 0 , tempState.ReadArray.Length,
new AsyncCallback(EndReadCallback), tempState);
// Concurrently do other work, such as
// logging the write operation.
}
static void EndWriteCallback( IAsyncResult^ asyncResult )
{
State^ tempState = dynamic_cast<State^>(asyncResult->AsyncState);
FileStream^ fStream = tempState->FStream;
fStream->EndWrite( asyncResult );
// Asynchronously read back the written data.
fStream->Position = 0;
asyncResult = fStream->BeginRead( tempState->ReadArray, 0, tempState->ReadArray->Length, gcnew AsyncCallback( &FStream::EndReadCallback ), tempState );
// Concurrently do other work, such as
// logging the write operation.
}
};
static void EndWriteCallback(IAsyncResult asyncResult)
{
State tempState = ((State)(asyncResult.get_AsyncState()));
FileStream fStream = tempState.get_FStream();
fStream.EndWrite(asyncResult);
// Asynchronously read back the written data.
fStream.set_Position(0);
asyncResult = fStream.BeginRead(tempState.get_ReadArray(), 0,
tempState.get_ReadArray().length ,
new AsyncCallback(EndReadCallback), tempState);
// Concurrently do other work, such as
// logging the write operation.
} //EndWriteCallback
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
FileStream 类
FileStream 成员
System.IO 命名空间