System.IO.StreamWriter.FlushAsyncInternal C# (CSharp) Method

FlushAsyncInternal() private method

private FlushAsyncInternal ( bool flushStream, bool flushEncoder, char sCharBuffer, int sCharPos ) : System.Threading.Tasks.Task
flushStream bool
flushEncoder bool
sCharBuffer char
sCharPos int
return System.Threading.Tasks.Task
        private Task FlushAsyncInternal(bool flushStream, bool flushEncoder,
                                        char[] sCharBuffer, int sCharPos)
        {
            // Perf boost for Flush on non-dirty writers.
            if (sCharPos == 0 && !flushStream && !flushEncoder)
            {
                return Task.CompletedTask;
            }

            Task flushTask = FlushAsyncInternal(this, flushStream, flushEncoder, sCharBuffer, sCharPos, _haveWrittenPreamble,
                                                _encoding, _encoder, _byteBuffer, _stream);

            _charPos = 0;
            return flushTask;
        }

Same methods

StreamWriter::FlushAsyncInternal ( StreamWriter _this, bool flushStream, bool flushEncoder, char charBuffer, int charPos, bool haveWrittenPreamble, Encoding encoding, Encoder encoder, Byte byteBuffer, Stream stream ) : System.Threading.Tasks.Task

Usage Example

Example #1
0
        // We pass in private instance fields of this MarshalByRefObject-derived type as local params
        // to ensure performant access inside the state machine that corresponds this async method.
        // Fields that are written to must be assigned at the end of the method *and* before instance invocations.
        private static async Task WriteAsyncInternal(StreamWriter _this, Char value,
                                                     Char[] charBuffer, Int32 charPos, Int32 charLen, Char[] coreNewLine,
                                                     bool autoFlush, bool appendNewLine)
        {
            if (charPos == charLen)
            {
                await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);

                Debug.Assert(_this.charPos == 0);
                charPos = 0;
            }

            charBuffer[charPos] = value;
            charPos++;

            if (appendNewLine)
            {
                for (Int32 i = 0; i < coreNewLine.Length; i++)   // Expect 2 iterations, no point calling BlockCopy
                {
                    if (charPos == charLen)
                    {
                        await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);

                        Debug.Assert(_this.charPos == 0);
                        charPos = 0;
                    }

                    charBuffer[charPos] = coreNewLine[i];
                    charPos++;
                }
            }

            if (autoFlush)
            {
                await _this.FlushAsyncInternal(true, false, charBuffer, charPos).ConfigureAwait(false);

                Debug.Assert(_this.charPos == 0);
                charPos = 0;
            }

            _this.CharPos_Prop = charPos;
        }
All Usage Examples Of System.IO.StreamWriter::FlushAsyncInternal