IsolatedStorageFileStream.IsAsync プロパティ
IsolatedStorageFileStream が非同期的に開かれたか、同期的に開かれたかを示す Boolean 値を取得します。
Overrides Public ReadOnly Property IsAsync As Boolean
[C#]
public override bool IsAsync {get;}
[C++]
public: __property bool get_IsAsync();
[JScript]
public override function get IsAsync() : Boolean;
プロパティ値
IsolatedStorageFileStream が非同期アクセスをサポートしている場合は true 。それ以外の場合は false 。
解説
FileStream と異なり、非同期の IsolatedStorageFileStream オブジェクトは作成できません。ただし、パフォーマンスは低下しますが、 BeginWrite, BeginRead, EndWrite および EndRead メソッドが同期インスタンスでサポートされています。
使用例
[Visual Basic, C#, C++] IsAsync プロパティを使用して、 IsolatedStorageFileStream が同期であることを確認する方法を、次のコード例に示します。この例のコンテキスト全体については、 IsolatedStorageFileStream の概要を参照してください。
Public Function SetNewPrefsForUser() As Double
Try
Dim inputChar As Byte
Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
' If this is not a new user, archive the old preferences and
' overwrite them using the new preferences.
If Not Me.myNewPrefs Then
If isoFile.GetDirectoryNames("Archive").Length = 0 Then
isoFile.CreateDirectory("Archive")
Else
Dim source As New IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate, isoFile)
Dim canWrite, canRead As Boolean
' This is the stream from which data will be read.
If source.CanRead Then canRead = True Else canRead = False
Console.WriteLine("Is the source file readable? " & canRead)
Console.WriteLine("Creating new IsolatedStorageFileStream for Archive.")
' Open or create a writable file.
Dim target As New IsolatedStorageFileStream("Archive\ " & Me.userName, _
FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write, isoFile)
' This is the stream to which data will be written.
If target.CanWrite Then canWrite = True Else canWrite = False
Console.WriteLine("Is the target file writable? " & canWrite)
target.SetLength(0) 'rewind the target file
' Stream the old file to a new file in the Archive directory.
If source.IsAsync And target.IsAsync Then
' IsolatedStorageFileStreams cannot be asynchronous. However, you
' can use the asynchronous BeginRead and BeginWrite functions
' with some possible performance penalty.
Console.WriteLine("IsolatedStorageFileStreams cannot be asynchronous.")
Else
Console.WriteLine("Writing data to the new file.")
While source.Position < source.Length
inputChar = CByte(source.ReadByte())
target.WriteByte(inputChar)
End While
' Determine the size of the IsolatedStorageFileStream
' by checking its Length property.
Console.WriteLine(("Total Bytes Read: " & source.Length))
End If
' After you have read and written to the streams, close them.
target.Close()
source.Close()
End If
End If
' Open or create a writable file with a maximum size of 10K.
Dim isoStream As New IsolatedStorageFileStream(Me.userName, FileMode.OpenOrCreate, _
FileAccess.Write, FileShare.Write, 10240, isoFile)
isoStream.SetLength(0) 'Position to overwrite the old data.
[C#]
public double SetNewPrefsForUser ()
{
try
{
byte inputChar;
IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore( IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain,
typeof(System.Security.Policy.Url),
typeof(System.Security.Policy.Url));
// If this is not a new user, archive the old preferences and
// overwrite them using the new preferences.
if (! this.myNewPrefs)
{
if ( isoFile.GetDirectoryNames("Archive").Length == 0 )
isoFile.CreateDirectory("Archive");
else
{
IsolatedStorageFileStream source =
new IsolatedStorageFileStream(this.userName,FileMode.OpenOrCreate,
isoFile);
// This is the stream from which data will be read.
Console.WriteLine("Is the source file readable? " + (source.CanRead?"true":"false"));
Console.WriteLine("Creating new IsolatedStorageFileStream for Archive.");
// Open or create a writable file.
IsolatedStorageFileStream target =
new IsolatedStorageFileStream("Archive\\ " + this.userName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.Write,
isoFile);
Console.WriteLine("Is the target file writable? " + (target.CanWrite?"true":"false"));
// Stream the old file to a new file in the Archive directory.
if (source.IsAsync && target.IsAsync)
{
// IsolatedStorageFileStreams cannot be asynchronous. However, you
// can use the asynchronous BeginRead and BeginWrite functions
// with some possible performance penalty.
Console.WriteLine("IsolatedStorageFileStreams cannot be asynchronous.");
}
else
{
Console.WriteLine("Writing data to the new file.");
while (source.Position < source.Length)
{
inputChar = (byte)source.ReadByte();
target.WriteByte(inputChar);
}
// Determine the size of the IsolatedStorageFileStream
// by checking its Length property.
Console.WriteLine("Total Bytes Read: " + source.Length);
}
// After you have read and written to the streams, close them.
target.Close();
source.Close();
}
}
// Open or create a writable file with a maximum size of 10K.
IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream(this.userName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.Write,
10240,
isoFile);
isoStream.Position = 0; // Position to overwrite the old data.
[C++]
double SetNewPrefsForUser ()
{
try
{
Byte inputChar;
IsolatedStorageFile* isoFile = IsolatedStorageFile::GetStore(
static_cast<IsolatedStorageScope>(IsolatedStorageScope::User |
IsolatedStorageScope::Assembly |
IsolatedStorageScope::Domain),
__typeof(System::Security::Policy::Url),
__typeof(System::Security::Policy::Url));
// If this is not a new user, archive the old preferences and
// overwrite them using the new preferences.
if (! this->NewPrefs)
{
if ( isoFile->GetDirectoryNames(S"Archive")->Length == 0 )
isoFile->CreateDirectory(S"Archive");
else
{
// This is the stream to which data will be written.
IsolatedStorageFileStream* source =
new IsolatedStorageFileStream(this->userName,FileMode::OpenOrCreate,
isoFile);
// This is the stream from which data will be read.
Console::WriteLine(S"Is the source file readable? {0}", (source->CanRead ? S"true" : S"false"));
Console::WriteLine(S"Creating new IsolatedStorageFileStream for Archive.");
// Open or create a writable file.
IsolatedStorageFileStream* target =
new IsolatedStorageFileStream((S"Archive\\ {0}", this->userName),
FileMode::OpenOrCreate,
FileAccess::Write,
FileShare::Write,
isoFile);
Console::WriteLine(S"Is the target file writable? {0}", (target->CanWrite ? S"true" : S"false"));
// Stream the old file to a new file in the Archive directory.
if (source->IsAsync && target->IsAsync)
{
// IsolatedStorageFileStreams cannot be asynchronous. However, you
// can use the asynchronous BeginRead and BeginWrite functions
// with some possible performance penalty.
Console::WriteLine(S"IsolatedStorageFileStreams cannot be asynchronous.");
}
else
{
Console::WriteLine(S"Writing data to the new file.");
while (source->Position < source->Length)
{
inputChar = (Byte)source->ReadByte();
target->WriteByte((Byte)source->ReadByte());
}
// Determine the size of the IsolatedStorageFileStream
// by checking its Length property.
Console::WriteLine(S"Total Bytes Read: {0}", source->Length.ToString());
}
// After you have read and written to the streams, close them.
target->Close();
source->Close();
}
}
// Open or create a writable file, no larger than 10k
IsolatedStorageFileStream* isoStream =
new IsolatedStorageFileStream(this->userName,
FileMode::OpenOrCreate,
FileAccess::Write,
FileShare::Write,
10240,
isoFile);
isoStream->Position = 0; // Position to overwrite the old data.
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
IsolatedStorageFileStream クラス | IsolatedStorageFileStream メンバ | System.IO.IsolatedStorage 名前空間 | FileStream