当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET IsolatedStorageFileStream.IsAsync属性代码示例

本文整理汇总了VB.NET中System.IO.IsolatedStorage.IsolatedStorageFileStream.IsAsync属性的典型用法代码示例。如果您正苦于以下问题:VB.NET IsolatedStorageFileStream.IsAsync属性的具体用法?VB.NET IsolatedStorageFileStream.IsAsync怎么用?VB.NET IsolatedStorageFileStream.IsAsync使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.IO.IsolatedStorage.IsolatedStorageFileStream的用法示例。


在下文中一共展示了IsolatedStorageFileStream.IsAsync属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: SetNewPrefsForUser

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.
开发者ID:VB.NET开发者,项目名称:System.IO.IsolatedStorage,代码行数:55,代码来源:IsolatedStorageFileStream.IsAsync


注:本文中的System.IO.IsolatedStorage.IsolatedStorageFileStream.IsAsync属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。