I am new to c#, building an android/iOS app. I have a IEnumerator function called at my activity OnCreate()
. But it never be called to execute.
private ICoroutine _startCoroutine;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
this._startCoroutine = CoroutineManager.Default.StartCoroutine(this.Start2());this
}
private IEnumerator Start2()
{
// things to do
}
I set a break point inside start(), but never trigged. What's the problem I have?
CoroutineManager
public sealed class CoroutineManager
{
public static CoroutineManager Default
{
get
{
return Coroutine;
}
}
public void StartCoroutine(IEnumerator routine)
{
if (routine == null)
{
throw new ArgumentNullException("routine");
}
StartCoroutine(routine);
}
}
Just create an example and it works:
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
CoroutineManager manager = new CoroutineManager();
manager.StartCoroutine(this.Start2());
}
private IEnumerator Start2()
{
Console.WriteLine("Start2");
ArrayList arr = new ArrayList();
return arr.GetEnumerator();
}
}
public class CoroutineManager
{
public CoroutineManager()
{
}
public void StartCoroutine(IEnumerator routine)
{
if (routine == null)
{
throw new ArgumentNullException("routine");
}
//StartCoroutine(routine);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.