question

guessmeifucan-8050 avatar image
0 Votes"
guessmeifucan-8050 asked ·

Need to execute a functionality twice on a single event.

In my scenario, my uwp app need to supports both online and offline mode. When an Event triggers and fetching data from the server, i need to serve the offline data in the mean time.

 function getData()
 {
     // calls the server for online data
     // return offline data
     // return online data 
 }
    
 function main()
 {
     var data = getData();
     processData(data);
     // ...
 }

In this case, when the main executes, getData() need to initiates the API call and return the offline data first and the main need to proceeds by processData(offlineData). Once getData() obtains the Online Data, it need to send the value back to main again and proceed by proceeds by processData(onlineData). Kindly assist me the way to acheive this requirement.


windows-uwp
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichardZhang-MSFT avatar image
0 Votes"
RichardZhang-MSFT answered ·

Hello,​

Welcome to our Microsoft Q&A platform!

I can provide an idea to solve your problem:

  1. Create getDataFromWeb() and getDataFromLocal() methods instead of the general getData() method.

  2. Create a global variable, assuming the variable name is totalData.

  3. First call getDataFromLocal() to assign the obtained value to totalData, and then continue to call getDataFromWeb(). If the value is obtained, assign the new value to totalData.

  4. Display the content of totalData on the UI by binding.

Here are some documents that might be helpful:

From the code you provided, the programming language you may use is Javascript. If so, you need to know Javascript about how to create Ajax requests.

Thanks.



· 5 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hai @RichardZhang-MSFT , Thanks for the reply. I'm using c#. Actually i'm aware of creating two separate classes and calling the both individually. As my application is a vast, it will be a big change for making every call for Data project (which holds all getData() methods) as twice ( once for offline then for online data). All i need is to send two datas from a method getData() as asynchronous, in a way that function call need to proceed the rest of the code with each data individually as a different thread.

0 Votes 0 ·

You seem to know how to do it, so what's problem you have meet? Is it possible to provide a minimally runnable demo to reproduce the problem, or provide the code in question?

0 Votes 0 ·

Hello, If you have any other questions, please feel free to contact us

0 Votes 0 ·

Hello, has your issue been resolved? Are there any other questions?

0 Votes 0 ·

Hello, does my reply solve your problem?

0 Votes 0 ·