O'Reilly logo

Xamarin Mobile Application Development for iOS by Paul F. Johnson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Starting a new thread from the main UI thread

A new thread coming from an existing thread is known as a daughter thread.

A very simple way to add a daughter thread on an iOS device is like this. I have first created a simple UI to show what is happening. The top label is called thread 1, the bottom label is called thread 2.

Starting a new thread from the main UI thread

The code also shows InvokeOnMainThread in action—without it the app fails:

using System.Threading; ... private int i = 0; public override void ViewDidLoad() { base.ViewDidLoad(); var first = new Thread(new ThreadStart(firstThread)); var second = new Thread(new ThreadStart(secondThread)); btnStart.TouchUpInside += delegate { first.Start(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required