This is a multi-part message in MIME format.

------=_NextPart_000_0008_01C6F459.ACA68A20
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi guys..

I've got a function that copies one file to another location. The file =
it copies is currently about 36mb. I've got an event being fired after =
after every 32k buffer read from FileStream.Read(), containing the bytes =
read thus far and the total bytes to read.

When I don't invoke to update the UI status, the copy currently =
completes in just under 3 seconds. With a UI status invoke, it takes 23 =
seconds.

Essentially this is my event handler:
if (this.InvokeRequired)
{
this.Invoke(new ProgressRaiseDelegate(progEvent), e);
}

And progEvent simply involves setting a progress bars value to the =
current value. Is there a way this can be significantly sped up? Cheers.

------=_NextPart_000_0008_01C6F459.ACA68A20
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.5700.6" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hi guys..</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I've got a function that copies one =
file to another=20
location. The file it copies is currently about 36mb. I've got an event =
being=20
fired after after every 32k buffer read from FileStream.Read(), =
containing the=20
bytes read thus far and the total bytes to read.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>When I don't invoke to update the UI =
status, the=20
copy currently completes in just under 3 seconds. With a UI status =
invoke, it=20
takes 23 seconds.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Essentially this is my event =
handler:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT color=3D#0000ff size=3D2>
<P><FONT face=3D"Courier New">if</FONT></FONT><FONT face=3D"Courier =
New"><FONT=20
size=3D2> (</FONT><FONT color=3D#0000ff size=3D2>this</FONT></FONT><FONT =
size=3D2><FONT=20
face=3D"Courier New">.InvokeRequired)<BR></FONT><FONT=20
face=3D"Courier New">{<BR>&nbsp;&nbsp;&nbsp; </FONT></FONT><FONT=20
face=3D"Courier New"><FONT color=3D#0000ff size=3D2>this</FONT><FONT=20
size=3D2>.Invoke(</FONT><FONT color=3D#0000ff size=3D2>new</FONT><FONT =
size=3D2>=20
</FONT><FONT color=3D#008080 =
size=3D2>ProgressRaiseDelegate</FONT></FONT><FONT=20
size=3D2><FONT face=3D"Courier New">(progEvent), e);<BR></FONT><FONT=20
face=3D"Courier New">}</FONT></FONT></P>
<P><FONT size=3D2><FONT face=3DArial>And progEvent simply involves =
setting a=20
progress bars value to the current value. Is there a way this can be=20
significantly sped up? Cheers.</FONT></P></FONT></DIV></BODY></HTML>

------=_NextPart_000_0008_01C6F459.ACA68A20--

Re: The cost of Invoke()... can it be done faster? by Stephany

Stephany
Fri Oct 20 00:23:52 CDT 2006

Calling Invoke will block you thread until 'progEvent' returns, thus causing
your delay.

Call BeginInvoke instaed which will allow your thread to continue
immediately.


"OPL" <no@thanks> wrote in message
news:O9YE51$8GHA.568@TK2MSFTNGP05.phx.gbl...
Hi guys..

I've got a function that copies one file to another location. The file it
copies is currently about 36mb. I've got an event being fired after after
every 32k buffer read from FileStream.Read(), containing the bytes read thus
far and the total bytes to read.

When I don't invoke to update the UI status, the copy currently completes in
just under 3 seconds. With a UI status invoke, it takes 23 seconds.

Essentially this is my event handler:
if (this.InvokeRequired)
{
this.Invoke(new ProgressRaiseDelegate(progEvent), e);
}
And progEvent simply involves setting a progress bars value to the current
value. Is there a way this can be significantly sped up? Cheers.



Re: The cost of Invoke()... can it be done faster? by Truong

Truong
Fri Oct 20 00:53:37 CDT 2006

There is 2 ways it can be improved:
- Call BeginInvoke, as Stephany pointed out
- Call it less often

OPL wrote:
> Hi guys..
>
> I've got a function that copies one file to another location. The file it copies is currently about 36mb. I've got an event being fired after after every 32k buffer read from FileStream.Read(), containing the bytes read thus far and the total bytes to read.
>
> When I don't invoke to update the UI status, the copy currently completes in just under 3 seconds. With a UI status invoke, it takes 23 seconds.
>
> Essentially this is my event handler:
> if (this.InvokeRequired)
> {
> this.Invoke(new ProgressRaiseDelegate(progEvent), e);
> }
>
> And progEvent simply involves setting a progress bars value to the current value. Is there a way this can be significantly sped up? Cheers.
>


Re: The cost of Invoke()... can it be done faster? by marc

marc
Sat Oct 21 16:45:51 CDT 2006

To expand on the "less often" option; firstly, you could simply fire
the event every <x> iterations (using a simple counter or module
operator); on the form, your event handler could simply update some
(synchronised) fields, and have a timer on the form check the fields
(again, synchronised) every (say) 500ms; using this approach, you a:
divorce UI and worker (except for the sync), and b: minimise the number
of messages on the queue (Invoke/BeginInvoke). At the end of the day,
the user isn't going to be able to read 200 updates a second... so
don't bother! For maximum performance, separate "reading the sync'd
fields" and "update the UI", e.g.

void Timer_Tick(...) {
string updatedStatus;
lock(SyncLock) {
updatedStatus = someField.ToString();
}
if(!string.IsNullOrEmpty(updatedStatus)) {
someControl.Text = updatedStatus;
}
}

void SomeWorker_StatusUpdated(...) {
lock(SyncLock) {
someField.AppendLine(newStatus);
}
}

Marc