Stream writing lags my GUI
I have a thread that dequeues data from a queue and write it to another appl开发者_如何转开发ication's STDIN. I'm using Stream, but with .Write and even .BeginWrite, when I send 1mb chunks to the second app, my GUI gets laggy for ~1sec. Why? My callbacks are something like this:
void Progress(object sender, ProgressArgs e) {
if (this.InvokeRequired) {
this.BeginInvoke(new MethodInvoker(delegate() { Progress(sender, e); }));
return;
}
progressBar1.Value = (int) e.PercentDone;
}
I would say, you're calling these callbacks too often, so that they clog your message queue with BeginInvoke
messages. Try saving the last received percent value and calling BeginInvoke
only when the new one is different from the last.
精彩评论