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

WriteAsyncInternal() private static method

private static WriteAsyncInternal ( StreamWriter _this, string value, char charBuffer, int charPos, int charLen, char coreNewLine, bool autoFlush, bool appendNewLine ) : System.Threading.Tasks.Task
_this StreamWriter
value string
charBuffer char
charPos int
charLen int
coreNewLine char
autoFlush bool
appendNewLine bool
return System.Threading.Tasks.Task
        private static async Task WriteAsyncInternal(StreamWriter _this, string value,
                                                     char[] charBuffer, int charPos, int charLen, char[] coreNewLine,
                                                     bool autoFlush, bool appendNewLine)
        {
            Debug.Assert(value != null);

            int count = value.Length;
            int index = 0;

            while (count > 0)
            {
                if (charPos == charLen)
                {
                    await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
                    Debug.Assert(_this._charPos == 0);
                    charPos = 0;
                }

                int n = charLen - charPos;
                if (n > count)
                {
                    n = count;
                }

                Debug.Assert(n > 0, "StreamWriter::Write(String) isn't making progress!  This is most likely a race condition in user code.");

                value.CopyTo(index, charBuffer, charPos, n);

                charPos += n;
                index += n;
                count -= n;
            }

            if (appendNewLine)
            {
                for (int 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;
        }

Same methods

StreamWriter::WriteAsyncInternal ( StreamWriter _this, char value, char charBuffer, int charPos, int charLen, char coreNewLine, bool autoFlush, bool appendNewLine ) : System.Threading.Tasks.Task
StreamWriter::WriteAsyncInternal ( StreamWriter _this, char buffer, int index, int count, char charBuffer, int charPos, int charLen, char coreNewLine, bool autoFlush, bool appendNewLine ) : System.Threading.Tasks.Task

Usage Example

Example #1
0
        public override Task WriteLineAsync(char[] buffer, int index, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer"));
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
            }
            if (buffer.Length - index < count)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
            }
            if (this.GetType() != typeof(StreamWriter))
            {
                return(base.WriteLineAsync(buffer, index, count));
            }
            if (this.stream == null)
            {
                __Error.WriterClosed();
            }
            this.CheckAsyncTaskInProgress();
            Task task = StreamWriter.WriteAsyncInternal(this, buffer, index, count, this.charBuffer, this.charPos, this.charLen, this.CoreNewLine, this.autoFlush, true);

            this._asyncWriteTask = task;
            return(task);
        }
All Usage Examples Of System.IO.StreamWriter::WriteAsyncInternal