Then I’m wondering: why would you want to execute something on  a separate 
thread in the first place, if all you do is wait until it finishes and do 
everything possible to *not* execute your code on the thread on which you 
currently are!?

 

René

 

Von: [email protected] 
[mailto:[email protected]] Im Auftrag von Chris Hatton
Gesendet: Freitag, 6. April 2012 15:55
An: [email protected]
Betreff: Re: [MonoTouch] When is BeginInvokeOnMainThread done?

 

Don't know how that happened! Yes the quote should of course read:

"InvokeOnMainThread will suspend the execution of your thread, and wait for the 
delegate to be executed on the main thread. When that completes, the thread 
resumes execution."

Seems this is the solution to the OP's question? Mojo can you confirm?

Thanks,
Chris

On 06/04/12 14:17, Alan wrote: 

Hey, 

 

You misquoted the site. "InvokeOnMainThread" blocks execution until the 
delegate is invoked. *Begin*InvokeOnMainThread does not.


Alan

On 6 April 2012 13:45, Chris Hatton <[email protected]> wrote:

Wouldn't plain 'InvokeOnMainThread' do what you are looking for?

>From the Wiki at: http://wiki.ios.xamarin.com/HowTo/Threading

"BeginInvokeOnMainThread will suspend the execution of your thread, and wait 
for the delegate to be executed on the main thread. When that completes, the 
thread resumes execution."

- Chris


On 06/04/12 07:00, René Ruppert wrote: 

I would opt for Task and ContinueWith(). It's an awesome way of dealing with 
such situations. 

All locking, WaitHandles or Sleep calls can block the UI thread on iPhone and 
cause very weird behavior or lockups. 

Grüße, René


Am 05.04.2012 um 23:34 schrieb Rodrigo Kumpera <[email protected]>:

You really can't do it without manually waiting for it. 

 

What you can do is:

 

object obj = new object ();

BeginInvokeOnMainThread (delegate {

 //Do something

 lock (obj) { Monitor.Notify (obj); }

});

Thread.Sleep (2000);

lock (obk) { Monitor.Wait (obj); }

 

Ideally we would provide wrappers for common idioms of the .NET plataform like 
making the

function return an IAsyncResult or Task object.

 

 

 

On Thu, Apr 5, 2012 at 6:13 PM, MojoDK <[email protected]> wrote:

Hi,

In this code...

ThreadPool.QueueUserWorkItem (delegate {
   BeginInvokeOnMainThread (delegate {
       // Do something
   });
   Thread.Sleep(2000);
   // Check something
});

... how can I make sure the "// Do something" is completely done before
"//Check something"?

In other words, how can I check when BeginInvokeOnMainThread is done and
then do some stuff still in the ThreadPool.QueueUserWorkItem?

Thanks!
Mojo

--
View this message in context: 
http://monotouch.2284126.n4.nabble.com/When-is-BeginInvokeOnMainThread-done-tp4536089p4536089.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

 

_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch





_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

 


_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

 

 

_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to