Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

298
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda