Speed executing a delegate

B

brambilla

Hi to all !

I develop in VB.NET 2005 an application for Windows CE 6.0 embedded
that run on an x86 device.

My question is:
is more speed executing a delegate (that modify some attributes of
controls created into primary thread) invoked from a secondary thread
or is more speed executing the same modification directly into primary
thread ?

For example:

Is more speed this:


Main Thread:
....
....
SecondaryThreadStart
....
....
InvokeDelegate
....
SecondaryThreadEnd

DelegateStart
....
SOMEMODIFICATION
....
DelegateEnd


Or is more speed this:

Main Thread:
....
SOMEMODIFICATION
....
SecondaryThreadStart
....
....
....
SecondaryThreadEnd


The SOMEMODIFICATION when is executing into primary/main thread and
when into secondary thread ?

Thankyou very much!
Ale
 
D

Dick Grier

When you invoke a delegate, you incure overhead. Thus, if the delegate is
not required for proper operation, inline code will be faster.

Use a delegate if you need it, and do not use it if it is not needed (a
generalization, but this applies to most design issues -- simpler is
better).

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
B

brambilla

When you invoke a delegate, you incure overhead.  Thus, if the delegateis
not required for proper operation, inline code will be faster.

Use a delegate if you need it, and do not use it if it is not needed (a
generalization, but this applies to most design issues -- simpler is
better).

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardandsoftware.netfor details and contact information.


Thanks Dick

but i make an error! The correct example is:

Is more speed this:

Main Thread:
....
....
SecondaryThreadStart
....
....
InvokeDelegate
....
SecondaryThreadEnd

DelegateStart
....
SOMEMODIFICATION
....
DelegateEnd


Or is more speed this:


Main Thread:
....
SOMEMODIFICATION
....
SecondaryThreadStart
....
....
InvokeDelegate
....
SecondaryThreadEnd

DelegateStart
....
....
DelegateEnd


(The delegate is needed for other instructions).

I have try an experiment: the first solution is better (the second is
less fast). Whi ?

Thankyou!
Ale
 
C

Chris Tacke, eMVP

Show us your test.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



When you invoke a delegate, you incure overhead. Thus, if the delegate is
not required for proper operation, inline code will be faster.

Use a delegate if you need it, and do not use it if it is not needed (a
generalization, but this applies to most design issues -- simpler is
better).

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
Seewww.hardandsoftware.netfor details and contact information.


Thanks Dick

but i make an error! The correct example is:

Is more speed this:

Main Thread:
....
....
SecondaryThreadStart
....
....
InvokeDelegate
....
SecondaryThreadEnd

DelegateStart
....
SOMEMODIFICATION
....
DelegateEnd


Or is more speed this:


Main Thread:
....
SOMEMODIFICATION
....
SecondaryThreadStart
....
....
InvokeDelegate
....
SecondaryThreadEnd

DelegateStart
....
....
DelegateEnd


(The delegate is needed for other instructions).

I have try an experiment: the first solution is better (the second is
less fast). Whi ?

Thankyou!
Ale
 
D

Dick Grier

Hi,

I'd need specific code to know "why."

Invoke calls the delegate immediately, while BeginInvoke causes creation a
thread that results in the delegate being called by the thread scheduler.

Depending on your needs, Invoke or BeginInvoke will be the appropriate
implementation.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top