System.IO.IsolatedStorage.IsolatedStorageFileStream.SetLength C# (CSharp) Méthode

SetLength() public méthode

public SetLength ( long value ) : void
value long
Résultat void
        public override void SetLength(long value) { }
        public override void Unlock(long position, long length) { }

Usage Example

Exemple #1
0
        /// <summary>
        /// Dequeue the first record 
        /// </summary>
        public static RequestRecord DequeueRequestRecord()
        {
            List<RequestRecord> requests = new List<RequestRecord>();
            DataContractJsonSerializer dc = new DataContractJsonSerializer(requests.GetType());

            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                lock (fileLock)
                {
                    using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(@"RequestRecords.xml", FileMode.Open, file))
                    {
                        try
                        {
                            // if the file opens, read the contents
                            requests = dc.ReadObject(stream) as List<RequestRecord>;
                            if (requests.Count > 0)
                            {
                                RequestRecord record = requests[0];
                                requests.Remove(record);  // remove the first entry
                                stream.SetLength(0);
                                stream.Position = 0;
                                dc.WriteObject(stream, requests);

                                record.DeserializeBody();
                                return record;
                            }
                            else
                                return null;
                        }
                        catch (Exception)
                        {
                            stream.Position = 0;
                            string s = new StreamReader(stream).ReadToEnd();
                            return null;
                        }
                    }
                }
            }
        }
All Usage Examples Of System.IO.IsolatedStorage.IsolatedStorageFileStream::SetLength