views:

60

answers:

1

I have a thread that dequeues data from a queue and write it to another application'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;
    }
A: 

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.

Fyodor Soikin
Good advice, but I'm sure the problem is from the .Write method because even if remove my callbacks to the gui, it still lags.
blez