开发者

Stream writing lags my GUI

开发者 https://www.devze.com 2022-12-31 00:12 出处:网络
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 se

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消