Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
969 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...