I have some understanding problem with an error message and hope someone can help me here. I try to implement a paypal payment. After the user has done his payment it can take a moment till my ipn script is called from paypal to finish the transaction. After the user called my payment website I want to poll my php file to get to know if the paypal transaction is available in my database. I thought this would be easy done this way: Code (CSharp): private void OpenWaitDialog () { aTimer = new System.Timers.Timer(30000); aTimer.AutoReset = true; aTimer.Elapsed += new System.Timers.ElapsedEventHandler(WaitTimeout); aTimer.Start(); m_bWaiting = true; StartCoroutine(CheckPayment(this)); } private void WaitTimeout(object source, ElapsedEventArgs e) { if (m_bWaiting == false) { aTimer.Stop(); return; } StartCoroutine(CheckPayment(this)); } private IEnumerator CheckPayment (CMyClass mainThread) { string strUrl; WWW www; strUrl = "www.myurl.de"; www = new WWW(strUrl); ... if(PaymentArrived) mainThread.m_bWaiting = false; ... } So far so well but when I play my game I get the error message "startcoroutine_auto can only be called from main thread". Can someone please tell me what I do wrong? so far I thought my first 2 methodes are working in the main thread and only the checkpayment methode was in another thread
WaitTimeOut is being called by your timer, that runs on another thread. To use this on the main thread have WaitTimeOut set a bool. Then check that bool in a coroutine started from the main thread. But to be honest you are better off simply running the timer in the coroutine with WaitFofSeconds.