Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
968 views
in Technique[技术] by (71.8m points)

xamarin.forms - Xamarin - How to process a growing queue on a background (non UI) thread

I'm writing an app using Xamarin Forms. The principal target platform will be Android for now. I have the following scenario and am looking for some guidance on how to approach it.

The app is used to scan barcodes (up to 40 or 50 per minute), this is not continuous. The data will come in bursts every 5 to 10 minutes. My problem is that processing each batch of scanned codes takes an average of 3-5 seconds on the server (depending on the number of codes in the batch).

I need to process a queue in order but I don't want to block the user inputting the data.

My initial thought was to use an IntentService, instantiating an Intent for each scanned code and add the code to a static ConcurrentQueue. I quickly realized that will not work since the intents themselves get queued up so my queue will never grow beyond 1 and ideally I want to send the data in batches to optimize the use of resources on the server.

My second thought was to have two IntentService classes, one to add items to a shared queue and the other to process the queue.

Am I missing something here? Is there a better way to do this?

To sumerize: I need to process a queue that can grow while it is being processed using Xamarin Forms for Android.

question from:https://stackoverflow.com/questions/65941602/xamarin-how-to-process-a-growing-queue-on-a-background-non-ui-thread

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...