question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow `Shell.Current.DisplayPromptAsync` to be cancelled with a `CancellationTokenSource`

See original GitHub issue

Description

I have a usecase, where a prompt is displayed and an input is required. If the input doesn’t happen in a specified time, the prompt should close and return null.

Public API Changes

await Shell.Current.DisplayPromptAsync(
"Input Unit",
"Waiting for robo to input the Unit.", x,x,x,
new CancellationTokenSource(TimeSpan.FromSeconds(30))
)

Intended Use-Case

When a CancellationTokenSource is passed, and it’s cancled (by timeout or whatever), the prompt should be closed and return null or an empty string.

Issue Analytics

  • State:open
  • Created 5 months ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
AndreasReitbergercommented, Apr 18, 2023

@rachelkang From what I can see, this should work. However I haven’t tested yet. I’ll do so tomorrow and close the issue if the suggestion works as intended 😃

Thank you @pictos

1reaction
pictoscommented, Apr 18, 2023

@AndreasReitberger you can use the new extension method called .WaitAsync, that should work.

await Shell.Current.DisplayPromptAsync("f", "f").WaitAsync(new CancellationTokenSource(TimeSpan.FromSeconds(30)).Token);

Read more comments on GitHub >

github_iconTop Results From Across the Web

DisplayPromptAsync Maui Cancel options
As the doc says: "If the Cancel button is tapped, null is returned.". Thus, ResultName.ToString() gives a null exception. Fix: check whether ...
Read more >
Task Cancellation
A successful cancellation involves the requesting code calling the CancellationTokenSource.Cancel method and the user delegate terminating ...
Read more >
Xamarin.Forms 4.4.0.991537 (4.4.0 Service Release 3) ...
Release notes detailing new features, improvements, and issues fixed in Xamarin.Forms 4.4.0.991537 (4.4.0 Service Release 3)
Read more >
Xamarin.Forms 5.0.0.2612
... public Task<string> DisplayPromptAsync(string title, string message, string accept, string cancel, string placeholder, int maxLength, Keyboard keyboard) ...
Read more >
Xamarin Forms Loading Popup
Popup: Allows you to create Xamarin. We released the Visual Studio extension for this tool in February and now a new version is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found