Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
Processing Dialog after QR Scan in Xamarin

I'm using QR Code Scanner in Xamarin App, when it scans the qr code, there are some operation it does which takes about a minute, while it's performing operation, I want to show a loading dialog on the screen. But, it isn't showing on the screen, and elsewhere in the app, it's working perfectly.

Code

var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
var opts = new ZXing.Mobile.MobileBarcodeScanningOptions { PossibleFormats = new List<ZXing.BarcodeFormat> { expectedFormat } };
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan(opts);
if (result == null)
{
    // code

    return null;
}
else
{
    using (UserDialogs.Instance.Loading("Processing"))
    {
        // code
    }
}

UPDATE CODE SAMPLE

public async Task Verification(object sender, EventArgs e)
{
    try
    {
        var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
        var opts = new ZXing.Mobile.MobileBarcodeScanningOptions { PossibleFormats = new List<ZXing.BarcodeFormat> { expectedFormat } };
        var scanner = new ZXing.Mobile.MobileBarcodeScanner();
        var result = await scanner.Scan(opts);
        if (result == null)
        {
            // Code
            
            return null;
        }
        else
        {
            try
            {
                // QR Scan Result
                string qr_scan = result.Response;

                var result = JsonConvert.DeserializeObject<QRScan>(qr_scan);

                await CreateConnection();
            }
            catch (Exception error)
            { }
            finally
            {
                // navigate to next page
                await NavigationService.NavigateToAsync<NextViewModel>();
            }
        }
    }
    catch (Exception error)
    { }

    return null;
}

public async Task CreateConnection()
{
    UserDialogs.Instance.Loading("Processing");
     
    if ()
    {
        try
        {
            // Code
        }
        catch (Exception error)
        {
            // Code
        }
        finally
        {
            await CreateFolder(default, default);
        }
    }
}

public async Task CreateFolder(object sender, EventArgs e)
{
    UserDialogs.Instance.Loading("Processing");

    try
    {
        // Code
    }
    catch (Exception error)
    {
        // Code
    }

    return null;
}  
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try something like this

Device.BeginInvokeOnMainThread(async () =>
{

    try
    {
        using (UserDialogs.Instance.Loading(("Processing")))
        {
            await Task.Delay(300);
                      
            //Your Service code
        }
    }
    catch (Exception ex)
    {
        var val = ex.Message;
        UserDialogs.Instance.Alert("Test", val.ToString(), "Ok");
    }
});
over 4 years ago · Santiago Trujillo Report

0

You can use Xamarin.Essentials' MainThread class and more specifically - the InvokeOnMainThreadAsync method. The idea of this method is to not only execute a code on the UI/main thread, but to also to await it's code. This way you can have both async/await logic and main thread execution.

try
{
    // QR Scan Result
    string qr_scan = result.Response;
    var result = JsonConvert.DeserializeObject<QRScan>(qr_scan);
    await MainThread.InvokeOnMainThreadAsync(() => CreateConnection());
}
catch (Exception error)
{ }
finally
{
    // navigate to next page
    await NavigationService.NavigateToAsync<NextViewModel>();
}

Keep in mind that if the method CreateConnection takes a long time to execute, then it would be better to execute on the main thread only the dialog presentation (UserDialogs.Instance.Loading("")).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!