IsolatedStorageFileStream.Close Método

Definição

Libera os recursos associados ao objeto IsolatedStorageFileStream.Releases resources associated with the IsolatedStorageFileStream object.

public:
 override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()

Exemplos

O exemplo de código a seguir demonstra o método Close.The following code example demonstrates the Close method.

IsolatedStorageFileStream source =
     new IsolatedStorageFileStream(this.userName,FileMode.Open,isoFile);
 // This stream is the one that data will be read from
 Console.WriteLine("Source can be read?" + (source.CanRead?"true":"false"));
 IsolatedStorageFileStream target =
     new IsolatedStorageFileStream("Archive\\ " + this.userName,FileMode.OpenOrCreate,isoFile);
 // This stream is the one that data will be written to
 Console.WriteLine("Target is writable?" + (target.CanWrite?"true":"false"));
 // Do work...
 // After you have read and written to the streams, close them
 source.Close();
 target.Close();
Dim source As New IsolatedStorageFileStream(UserName,FileMode.Open,isoFile)
 ' This stream is the one that data will be read from
 If source.CanRead Then
     Console.WriteLine("Source can read ? true")
 Else
     Console.WriteLine("Source can read ? false")
 End If
 Dim target As New IsolatedStorageFileStream("Archive\\ " & UserName, _
                                             FileMode.OpenOrCreate, _
                                             isoFile)
 ' This stream is the one that data will be written to
 If target.CanWrite Then
     Console.WriteLine("Target is writable? true")
 Else
     Console.WriteLine("Target is writable? false")
 End If
 ' After you have read and written to the streams, close them
 source.Close()
 target.Close()

Comentários

Todos os dados gravados anteriormente no buffer são copiados para o arquivo antes de o fluxo de arquivos ser fechado, portanto, não é necessário chamá-lo Flush antes de invocar o fechamento.Any data previously written to the buffer is copied to the file before the file stream is closed, so it is not necessary to call Flush before invoking Close.

Após uma chamada para Close, todas as operações no fluxo de arquivos podem gerar exceções.Following a call to Close, any operations on the file stream might raise exceptions. Depois que Close o for chamado uma vez, ele não fará nada se for chamado novamente.After Close has been called once, it does nothing if called again. O Finalize() método invoca o Close para que o fluxo de arquivos seja fechado antes que o coletor de lixo Finalize o objeto.The Finalize() method invokes Close so the file stream is closed before the garbage collector finalizes the object.

IsolatedStorageFileStream os objetos exigem um IsolatedStorageFile objeto que determina o contexto de armazenamento para os arquivos acessados.IsolatedStorageFileStream objects require an IsolatedStorageFile object that determines the storage context for the files accessed. Para fluxos abertos sem passar um IsolatedStorageFile objeto, um IsolatedStorageFile objeto padrão é criado para o assembly em execução e, em seguida, fechado durante a chamada para fechar.For streams opened without passing an IsolatedStorageFile object, a default IsolatedStorageFile object is created for the executing assembly and then closed during the call to Close.

Observação

O Close método chama Dispose with disposição definido como true para liberar seus recursos e, em seguida, chama SuppressFinalize para suprimir a finalização desse objeto pelo coletor de lixo.The Close method calls Dispose with disposing set to true to release its resources, then calls SuppressFinalize to suppress finalization of this object by the garbage collector.

Aplica-se a