/// <summary>
        ///     Implements IDebugOutputCallbacks2::Output2
        /// </summary>
        public int Output2(DEBUG_OUTCB Which, DEBUG_OUTCBF Flags, UInt64 Arg, string Text)
        {
            var mask = (DEBUG_OUTPUT)Arg;

            if (Which == DEBUG_OUTCB.EXPLICIT_FLUSH)
            {
                //Flush();
                return(S_OK);
            }
            if (string.IsNullOrEmpty(Text))
            {
                return(S_OK);
            }
            bool textIsDml = (Which == DEBUG_OUTCB.DML);

            if (OutputActive)
            {
                lock (this)
                {
                    OutputActive       = false;
                    PreviousTextWasDml = textIsDml;
                    PreviousDmlFlags   = Flags;
                    DbgStringBuilder LineBuffer;
                    LineBuffers.TryGetValue(mask, out LineBuffer);
                    int LineInputPos = 0;
                    LineInputPositions.TryGetValue(mask, out LineInputPos);
                    bool waitForClosingDML = false;

                    if (LineBuffer == null)
                    {
                        LineBuffer        = new DbgStringBuilder(ExecutionUtilities, 1024);
                        LineBuffers[mask] = LineBuffer;
                    }
                    for (int i = 0; i < Text.Length; ++i)
                    {
                        char c = Text[i];
                        if (c == '<')
                        {
                            waitForClosingDML = true;
                        }
                        if (waitForClosingDML)
                        {
                            if (c == '>')
                            {
                                waitForClosingDML = false;
                            }
                        }
                        if (c == '\n' && waitForClosingDML == false)
                        {
                            LineBuffer.AppendLine();
                            ProcessLine(mask, LineBuffer.ToString(), textIsDml, Flags);
                            LineBuffer.Clear();
                            LineInputPos = 0;
                        }
                        else if (c == '\r')
                        {
                            LineInputPos = 0;
                        }
                        else
                        {
                            if (LineInputPos >= LineBuffer.Length)
                            {
                                LineBuffer.Append(c);
                            }
                            else
                            {
                                LineBuffer[LineInputPos] = c;
                            }
                            ++LineInputPos;
                        }
                    }

                    LineInputPositions[mask] = LineInputPos;

                    OutputActive = true;
                }
            }

            return(S_OK);
        }