I got following code executing at a ~1000ms rate. Left alone, it causes a weird "thread leak". Using WindDBG/SoS I am able to see waaay to many ThreadPool Worker threads (some of them are marked as dead) and eventually I will get a AccessVioalation Exception. Can anybody tell me if my BeginInvoke/EndInvoke use is wrong, unnecessary lock perhaps ... any clues will help as I am ... well, clueless at this point
RichTextBox tmpBox = txtIncomingData;
lock (m_TextUpdateSynch) {
try {
result = Utilities.SafeBeginInvoke(this, delegate() {
try {
if (tmpBox.Text.Length > BufferSize) {
tmpBox.Text = rawData;
}
else {
tmpBox.AppendText(rawData);
}
pageBottom(txtIncomingData);
}
catch (...) {}
});
this.EndInvoke(result);
}
public static IAsyncResult Utilities.SafeBeginInvoke(System.ComponentModel.ISynchronizeInvoke control,
ControlUpdate action, AsyncCallback callback,
params object[] args) {
IAsyncResult result = null;
Control uiControl = control as Control;
try {
result = control.BeginInvoke(action, args);
}
catch (...) { }
return result;
}