System.IO.Pipes.PipeStream.Flush C# (CSharp) Méthode

Flush() public méthode

public Flush ( ) : void
Résultat void
        public override void Flush() { }
        public override int Read(byte[] buffer, int offset, int count) { throw null; }

Usage Example

Exemple #1
0
        /// <summary>
        /// Überträgt ein Objekt in eine Kommunikationseinheit.
        /// </summary>
        /// <param name="pipe">Die Kommunikationseinheit.</param>
        /// <param name="serializer">Die Serialisierungsinstanz.</param>
        /// <param name="instance">Das betroffene Objekt.</param>
        internal static void SendToPipe( PipeStream pipe, XmlSerializer serializer, object instance )
        {
            // Create helper
            using (var temp = new MemoryStream())
            {
                // Create writer configuration
                var settings = new XmlWriterSettings { CheckCharacters = false };

                // Create
                using (var writer = XmlWriter.Create( temp, settings ))
                    serializer.Serialize( writer, instance );

                // Read data and create buffer for length
                var len = new byte[sizeof( long )];
                var data = temp.ToArray();

                // Lock briefly
                var lenLock = GCHandle.Alloc( len, GCHandleType.Pinned );
                try
                {
                    // Fill
                    Marshal.WriteInt64( lenLock.AddrOfPinnedObject(), data.LongLength );
                }
                finally
                {
                    // Release
                    lenLock.Free();
                }

                // Send all
                pipe.Write( len, 0, len.Length );

                // Write in blocks
                for (int n = 0; n < data.Length; )
                {
                    // Block size
                    int block = Math.Min( BlockSize, data.Length - n );

                    // Send chunck
                    pipe.Write( data, n, block );
                    pipe.Flush();

                    // Advance
                    n += block;
                }

                // Flush
                pipe.Flush();
                pipe.WaitForPipeDrain();
            }
        }
All Usage Examples Of System.IO.Pipes.PipeStream::Flush