Problem :-
I am using C# Web API's
to create new users.
Whenever I create a new user and sends first request to save data on Algolia
Index
from that new user it does not save data on Algolia
Index
.
But at second request it works and saves the data, any idea what could be the reason?
Everything works fine on local solution but when I deploy project problem occurs but just for very first time. Here are both scenarios for which issue is occuring
I have tried :-
I am using free version of Algolia , I have contacted with support they have offered two solutions.
One is to put Wait()
after asynchronous
call, this solution worked for sorting because there was inconsistency of same kind for sorting but this solution did not work for SaveObject()
Second solution they offered is to use paid version of Algolia :(
Algolia Code in C# :-
var createFeed = await feedIndex.SaveObjectAsync(feedDocumentObject);
createFeed.Wait();
Please, think about to call the second Task using ContinueWith approach, if your requirement is guarantees the second step of your code will be executed after first step, this sample bellow has a little bit of how to your code be changed (conceptually, considering the object feedIndex is a FeedIndexType in C# code):
Task<FeedIndexType> step1 = Task.Run<FeedIndexType>(() =>
{
//first step
return feedIndex;
});
var createFeed = step1.ContinueWith((feedIndex) =>
{
feedIndex.SaveObjectAsync(feedDocumentObject);
});
createFeed.Wait();
You may see more about this approach in this article: Difference Between Await and ContinueWith Keyword in C# and Chaining Tasks by Using Continuation Tasks