Exemplo n.º 1
0
 private void PersistToDisk(object theObject)
 {
     using (this.persistedToDiskRegion.UseEnterScope())
     {
         try
         {
             object persistBackgroundSync = PersistedObject <T> .persistBackgroundSync;
             lock (persistBackgroundSync)
             {
                 using (FileStream stream = new FileStream(this.tempFileName, FileMode.Create, FileAccess.Write, FileShare.Read))
                 {
                     BinaryFormatter formatter             = new BinaryFormatter();
                     KeyValuePair <object, object>[] items = new KeyValuePair <object, object>[] { KeyValuePairUtil.Create <object, object>(MemoryBlock.UseCompressionBooleanDeferredFormatterKey, true) };
                     DeferredFormatter additional          = new DeferredFormatter(null, ArrayUtil.Infer <KeyValuePair <object, object> >(items));
                     StreamingContext  context             = new StreamingContext(formatter.Context.State, additional);
                     formatter.Context = context;
                     formatter.Serialize(stream, theObject);
                     additional.FinishSerialization(stream);
                     stream.Flush();
                 }
             }
         }
         finally
         {
             this.theObjectSaved.Set();
             this.theObjectSaved = null;
         }
         GC.KeepAlive(theObject);
     }
 }