How to continue in Device.BeginInvokeOnMainThread

영훈 정 281 Reputation points
2022-12-01T08:45:09.36+00:00
do  
            {  
                Device.BeginInvokeOnMainThread(async () =>  
                {  
                    // [진행률 업뎃]  
                    this.xProgress.SetProgressValue(nIndex++);  
  
  
                    // [시작시간부터 지정 시간까지 측정하지 않고 대기]  
                    //if (dtEndTime > DateTime.Now + this.m_MethodInfo.OffsetTime && m_bStop == false)  
                    if (DateTime.Now < dtOffset && m_bStop == false)  
                    {  
                        await continue;  
                    }  
  
  
  
                    // [MeasureMain에 측정을 요청]  
                    if (this.EventRequestFromKit != null)  
                        this.EventRequestFromKit(RequestFromKit.StartInspection, this.ItemType);  
                });  
  
  
  
                // [인터벌 만큼 쉬자]  
                //await Task.Delay(this.m_MethodInfo.Interval);   
                await Task.Delay(2000);  
            }  
            while ((dtEndTime > DateTime.Now) && m_bStop == false);  

I have code like this:
I used BeginInvokeOnMainThread inside the while statement.

When I try to continue according to certain conditions, error CS1632 occurs. Is there a way to use Continue inside BeginInvokeOnMainThread?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,291 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 35,021 Reputation points Microsoft Vendor
    2022-12-02T03:24:26.68+00:00

    Hello,

    Yes, to be precise, continue cannot be used in lambda expressions. This is because do while and continue are not actually in the same function body and have different scopes.

    You could use return instead of continue in lambda expressions.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful