0

I have an application where I need to do two I/O tasks: get a GPS location, retrieve some data over Bluetooth. Both tasks can vary in time to complete, and can take many seconds. To improve the speed of the application I want to kick-off both activities at the same time, and then wait for both to complete before proceeding.

If I do this:

bool locationStatus= await GetCurrentLocation(); bool vehicleStatus = await GetVehicleData(); 

does the second function get kicked off, or is it only the UI that is not blocked?

Do I need to invoke parallel tasks instead?

4
  • 2
    There was a duplicate question a few hours ago. There are a lot of similar questions with great explanations. Please search for a solution first before posting. Commented Jan 26, 2018 at 10:41
  • I know it is not the fast answer you seek, but I believe you should invest in studying this. gist.github.com/staltz/868e7e9bc2a7b8c1f754 Commented Jan 26, 2018 at 10:42
  • 1
    By asking for something that's already been answered 100 times you won't get good answers - people become tired of answering the same thing after a while. Instead of the great explanation they wrote 1 year ago they'll only post a short answer Commented Jan 26, 2018 at 10:42
  • @itdoesntwork that link is unrelated to the question. Rx isn't meant for asynchronous programming anyway, it's meant for event stream processing, even if other languages like Java use it this way because they lack async/await support Commented Jan 26, 2018 at 10:43

1 Answer 1

6

You are directly awaiting the first function. If you want to let the functions complete asynchronous, you will have to put the await at the position where you need the variables.

For example:

var locationStatus = GetCurrentLocation(); var vehicleStatus = GetVehicleData(); if (await locationStatus && await vehicleStatus) { // Do stuff } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.