473,394 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Invoke() execution

Suppose you call

this.Invoke(new MyDelegate(MyMethod));
this.Invoke(new MyDelegate(MyMethod2));

(assume not calling from owning thread so marshall occurs)

Is MyMethod *guaranteed* to finish execution before MyMethod2 starts?

Regards

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
6 1467
If the mydelegate was async the method then it would kick off a new thread
and return. It could then do the same for the second line. Splitting hairs
here but the mydelegate method completed starting a new thread in a
different VM's sync. The threads that actually are carrying out the work in
different VM's are not dependent on eachother. They could be on different
machines.

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

"vooose" <no****@microsoft.com> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
Suppose you call

this.Invoke(new MyDelegate(MyMethod));
this.Invoke(new MyDelegate(MyMethod2));

(assume not calling from owning thread so marshall occurs)

Is MyMethod *guaranteed* to finish execution before MyMethod2 starts?

Regards

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #2
Yahoo <jo***************@yahoo.com> wrote:
If the mydelegate was async the method then it would kick off a new thread
and return. It could then do the same for the second line. Splitting hairs
here but the mydelegate method completed starting a new thread in a
different VM's sync. The threads that actually are carrying out the work in
different VM's are not dependent on eachother. They could be on different
machines.


Delegates themselves aren't synchronous or asynchronous - they're just
invoked in a synchronous or asynchronous way.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
vooose <no****@microsoft.com> wrote:
Suppose you call

this.Invoke(new MyDelegate(MyMethod));
this.Invoke(new MyDelegate(MyMethod2));

(assume not calling from owning thread so marshall occurs)

Is MyMethod *guaranteed* to finish execution before MyMethod2 starts?


Well, you haven't said what "this" is - if it's a control, for
instance, then yes, MyMethod will definitely finish before Invoke
returns.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Thanks for your replies. "this" is a Control - I should have clarified
that initially. What about if you replace Invoke with BeginInvoke? I
realise this executes it async but since MyMethod was marshalled before
MyMethod2 shouldnt it always finish first as well (ie MyMethod gets hold
of the underlying window thread first ALWAYS)

Regards

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #5
"vooose" <no****@microsoft.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Thanks for your replies. "this" is a Control - I should have clarified
that initially. What about if you replace Invoke with BeginInvoke? I
realise this executes it async but since MyMethod was marshalled before
MyMethod2 shouldnt it always finish first as well (ie MyMethod gets hold
of the underlying window thread first ALWAYS)

Regards

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***


I'm pretty sure it will using BeginInvoke - however I always feel a bit
uncomfortable about relying on this type of behavior. If you really want the
two methods to execute in Method1, Method2 order, use BeginInvoke on a
method that executes Method1 and Method2 synchronously. It will certainly
make youo intention clearer to anyone looking at the code.
Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Nov 17 '05 #6
It is posting to a fifo queue so not sure under what circumstances it would
not work in order posted.

--
William Stacey [MVP]

"vooose" <no****@microsoft.com> wrote in message
news:ey**************@tk2msftngp13.phx.gbl...
Thanks for your replies. "this" is a Control - I should have clarified
that initially. What about if you replace Invoke with BeginInvoke? I
realise this executes it async but since MyMethod was marshalled before
MyMethod2 shouldnt it always finish first as well (ie MyMethod gets hold
of the underlying window thread first ALWAYS)

Regards

--
Wal
http://www.vooose.com

*** Sent via Developersdex http://www.developersdex.com ***

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kishore | last post by:
Hi, I have a small console application written in c# that takes two arguments. I am using System.Diagnostics.Process.Start("cmdApp.exe", arguments) to start the application from another .net...
6
by: Vladimir | last post by:
May be it's not obvious what am i asking for... I have 2 threads in my application. The first thread responds for the user interface and sending key combinations, the second thread listening...
2
by: kapila Wijethilaka | last post by:
Hello, I want to invoke clients iExplorer from my axpx page. I did a some cod eto dot this.but it gave me below error. can anybody help me with this thanks Access is denied.
7
by: brisers | last post by:
Hello, After studying some of the available resouces ( http://msdn.microsoft.com/msdnmag/issues/04/05/BasicInstincts/default.aspx) I can see that it is forbidden to modify the UI directly from...
15
by: Oleg Subachev | last post by:
I need to programmatically invoke from other class Click event of the Button on my Form. Button.OnClick method is protected, not public. How to perform this ? Oleg Subachev
11
by: cindy | last post by:
I have a form, has javascript registered so a modal pops up. Button click will close form. Now I need to do an update with modal form data before it closes. I can put a second button and register...
5
by: PiotrKolodziej | last post by:
Hi. I have a form. This form calls thread. Inside this thread i have while loop: while ((bufferCount = FileStream.Read(buffer, 0, 64000)) 0 && !Stop) { store += bufferCount;...
3
by: Ole | last post by:
Hi, I have an instance of a class in which a thread is running. When a special condition in that instance is met it raises an event to my main class (UI), but I can't directly interact with the...
2
by: LVP | last post by:
Hello, How does Control.Invoke(delegate) work? Executes the specified delegate on the thread that owns the control's underlying window handle I am looking for Underthehood explanation. How...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.