Esempio n. 1
0
        public OutputForm(MyTraceListener listener)
        {
            this.Controls.Add(TXB);
            this.Size = new System.Drawing.Size(700, 500);
            Queue <Tuple <Delegate, object[]> > toInvoke = new Queue <Tuple <Delegate, object[]> >();

            this.FormClosing += OutputForm_FormClosing;
            {
                MyTraceListener.NewMsgEventHandler f = null;
                f = new MyTraceListener.NewMsgEventHandler((msg, indent) =>
                {
                    if (InvokeRequired)
                    {
                        TXB.Invoke(new Action(() =>
                        {
                            EnsureIndent(indent + 1);
                            msgs[indent] += msg;
                            ShowMsg();
                        }));
                        return;
                        //toInvoke.Enqueue(new Tuple<Delegate, object[]>(new MyTraceListener.NewMsgEventHandler(f), new object[] { msg, indent }));
                        //return;
                    }
                    if (toInvoke.Count > 0)
                    {
                        var v = toInvoke.Dequeue();
                        Invoke(v.Item1, v.Item2);
                    }
                    EnsureIndent(indent + 1);
                    msgs[indent] += msg;
                    ShowMsg();
                });
                listener.NewMsg += f;
            }
            {
                MyTraceListener.NewLineEventHandler f = null;
                f = new MyTraceListener.NewLineEventHandler((msg, indent) =>
                {
                    if (InvokeRequired)
                    {
                        TXB.Invoke(new Action(() =>
                        {
                            EnsureIndent(indent);
                            msgs.Add(/*new string('\t', msgs.Count) +*/ msg);
                            ShowMsg();
                        }));
                        return;
                        //toInvoke.Enqueue(new Tuple<Delegate, object[]>(new MyTraceListener.NewLineEventHandler(f), new object[] { msg, indent }));
                        //return;
                    }
                    if (toInvoke.Count > 0)
                    {
                        var v = toInvoke.Dequeue();
                        Invoke(v.Item1, v.Item2);
                    }
                    EnsureIndent(indent);
                    msgs.Add(msg);
                    ShowMsg();
                });
                listener.NewLine += f;
            }
        }