0

我正在为一个更大的程序制作一个 GUI。为了包含一个中止按钮,我不得不使用 Backgroundworker。

void _oWorker_DoWork(object sender, DoWorkEventArgs e)
        {           
            try
            {
                Starter.Handling(cBLog, cBSelC, cBSelT);
                if (_oWorker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message,"Exception Caught:");
            }
        }

但是现在我偶然发现了一个更大的问题,无法访问加载如下的文本框:

private void Form1_Load(object sender, EventArgs e)
    {
        // Instantiate the writer
        _writer = new TextBoxStreamWriter(txtConsole);
        // Redirect the out Console stream
        Console.SetOut(_writer);
    }

问题是,TextBox 必须保留控制台输出,因为我不想更改子程序(其中也包含 while 循环)。有什么建议么?

4

0 回答 0