아래 표시된 사용자 지정 TraceListener의 출력으로 사용하는 RichTextBox가 있습니다. 다른 사람이 디버그/추적 정보를 쓰는 경우 어려움이 있습니다. GUI 대화 상자도 디버그/추적 정보를 쓰려고합니다.RichTextBox에 사용자 지정 System.Diagnostics.TraceListener 출력이 중단되었습니다.
누구나 여기서 명백한 오류를 지적 할 수 있습니까? :
class MyTraceListener : TraceListener
{
private RichTextBox output;
public MyTraceListener (RichTextBox output) {
this.Name = "DebugTrace";
this.output = output;
}
public override void Write(string message) {
Action append = delegate() { output.AppendText(message); };
if (output.InvokeRequired) {
IAsyncResult result = output.BeginInvoke(append);
output.EndInvoke(result);
} else {
append();
}
}
public override void WriteLine(string message) {
Action append = delegate() { output.AppendText(message + "\r\n"); };
if (output.InvokeRequired) {
IAsyncResult result = output.BeginInvoke(append);
output.EndInvoke(result);
} else {
append();
}
}
}
BeginInvoke 만 호출하면 교착 상태가 발생하는 것을 제외하고는 본질적으로 동일한 클래스를 작성했습니다. AFAIK에서는 EndInvoke를 호출 할 필요가 없습니다. do not는 inv의 결과를 신경 쓰지 않는다. 알았어. –
글쎄, 그래서에 대한 다른 논의 EndInvoke 전화해야 나타냅니다. 그러나 여기서 일어나는 일들은 EndInvoke에서의 블로킹을 피하면서 정말로 잠그지 않습니다. –