Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / November 2007

Tip: Looking for answers? Try searching our database.

Order of message posts through BeginInvoke preserved?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff Newman - 28 Nov 2007 15:19 GMT
Does anyone know if the order of delegate calls onto a thread through
BeginInvoke are guaranteed to come in the same order that they are
placed?  For example, if the following calls happen in order:

control.BeginInvoke(new InvokeDelegate(functionOne));
control.BeginInvoke(new InvokeDelegate(functionTwo));

Is there now a guarantee that functionOne will be executed before
function two on the thread that created control?  Does this hold if
the code above happens to be executing on the same thread that is
being invoked upon (ie control.InvokeRequired == false)?

This seems like an obvious question to me (that the order would be
preserved), but we're seeing some behavior that appears to indicate
otherwise and I'm trying to cover our bases.

Thanks!
<ctacke/> - 28 Nov 2007 16:00 GMT
I would suspect that the order is undefined for asynchronous operations.
Being async, the calls are likely marshalled to a separate thread for
execution.  if multiple calls are made, then you have multiple threads, all
running at the same priority.  In *most* cases they would get processed in
the order they were given to the scheduler, however there's nothing that
says that if the scheduler processes a higher priority thread (like a
driver) that when it comes back to the apps priority that it has to do them
in any order.  It just round-robins all waiting threads at that priority.
You shouldn't make any assumption about the order that they will run - if
the order is important, you should enforce it through synchronization
objects.

Signature

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com

> Does anyone know if the order of delegate calls onto a thread through
> BeginInvoke are guaranteed to come in the same order that they are
[quoted text clipped - 13 lines]
>
> Thanks!
stealthrabbi - 30 Nov 2007 13:05 GMT
Doesn't the windows message pump work like a queue, which would
suggest that it would process them in order?

http://www.codeproject.com/csharp/begininvoke.asp

> I would suspect that the order is undefined for asynchronous operations.
> Being async, the calls are likely marshalled to a separate thread for
[quoted text clipped - 30 lines]
>
> > Thanks!
<ctacke/> - 30 Nov 2007 14:33 GMT
Yes, but you're assuming that they *get* to the queue in the same order that
you call Invoke for the reasons I've outlined.  I don't think you can
guarantee that - I sure wouldn't rely on it.  Again, you should never make
any assumption about the order of asynchronous processing.  If you need
there to be some rigid order, you should enforce it, not just hope that
things will somehow work out.

Signature

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com

> Doesn't the windows message pump work like a queue, which would
> suggest that it would process them in order?
[quoted text clipped - 38 lines]
>>
>> > Thanks!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.