예제 #1
0
        public ConsoleForm InitializeConsoleFormWriter()
        {
            var f = this;

            var w = new ConsoleForm_TextWriter();

            var o = Console.Out;

            Console.SetOut(w);

            w.AtWrite =
                x =>
                {
                    f.textBox1.AppendText(x.Replace("\r", "").Replace("\n", "\r\n"));
                    o.Write(x);
                    f.textBox1.ScrollToCaret();
                };

            w.AtWriteLine =
                x =>
                {
                    // IE is special
                    f.textBox1.AppendText(x + "\r\n");
                    //f.textBox1.AppendText(x + Environment.NewLine);
                    o.WriteLine(x);
                    f.textBox1.ScrollToCaret();
                };

            return this;
        }
        public static DedicatedWorkerGlobalScope RedirectConsoleOutput(this DedicatedWorkerGlobalScope worker)
        {
            {
                #region ConsoleFormWriter
                var w = new ConsoleForm_TextWriter();

                var o = Console.Out;

                Console.SetOut(w);

                w.AtWrite =
                     x =>
                     {
                         worker.postMessage(x);
                     };

                w.AtWriteLine =
                    x =>
                    {
                        worker.postMessage(x + Environment.NewLine);
                    };
                #endregion
            }

            return worker;

        }