Not receiving OnSendPrivateUpdateDone callback unless I use a breakpoint

0 votes
Hello,

I am developing an application for Windows Phone 8.1 and Windows 8.1 using WinRT and the AppWarp SDK. I am trying to use the SendPrivateUpdate function to send data to another online user but for some reason I am not getting a callback on my actual devices (Nokia Lumia 1020 and Nokia Lumia 920) unless I am debugging and set a breakpoint on the OnSendPrivateUpdateDone callback. As soon as I remove the breakpoing I stop receiving the callback (I have a print statement everytime I get the callback and it never shows up). On the emulator running on my computer everything is working properly.  Is there any idea on how to fix this issue?
asked May 4, 2014 in AppWarp by feraask (45 points)
edited May 4, 2014 by feraask

1 Answer

0 votes
Could it be because the callback's come on a background thread and not the main thread? Are you writing on the console or on the UI?
answered May 4, 2014 by dhruvc (1,099 points)
The way I have my app set up is as follows:
- I have a global class with a static bool variable called SendComplete which I initialize to false
- When the user opens the app they put in their credentials and press the login button which then calls Frame.Navigate(typeof(MainPage)) and opens my MainPage
- In the MainPage LoadState event I call warpClient.SendPrivateUpdate and then I do await Task.Run( () => { while (SendComplete == false) ; });
- In the SendPrivateUpdate callback once it completes I set the SendComplete variable = true so that the main thread can continue but I never receive the callback so my main thread just stays waiting forever

I have a print statement which prints a MessageDialog to the UI. I've tried putting it right before the call to SendPrivateUpdate and it is definitely being reached. I then tried putting a print statement in the OnSendPrivateUpdateDone callback and it never happens. What is strange is that this works exactly as it should on the emulator on my computer but not on my actual devices unless I put run it on my device through the debugger and put a breakpoint in the callback as I mentioned.
Okay so I've tested further and found that if instead of sending the updates on the NavigationHelper_LoadState event for the MainPage I simply create a button on the MainPage that does the exact same thing and press it when the page shows up on the device it works fine and sends the updates and I get the callback. So why does it not work when I try to send the updates in the LoadState method that is run automatically when the page is navigated to?

I even tried setting a Loaded event on the main Page element on my MainPage.xaml and it still didn't work there. The only way I can seem to get the updates to actually send and then receive the callback is if I use a button that is clicked by the user. This is obviously non-ideal as I would like for this to occur automatically when the page is navigated to. Is there anyway around this?
So I've tried removing as much threading as possible. I've moved all the API calls into the LoginButton_Click event and basically before each API call I set a variable unique to that specific function to false (so, for example, the connect function has a bool connectComplete = false) and then I call the API and then I loop waiting for the variable to be set to true. So basically the way I am sending private updates is:

GlobalContext.sendUpdateComplete = false;
GlobalContext.warpClient.SendPrivateUpdate(username, bytesOfData);
while (sendUpdateComplete == false) ;
PrintMessage("Sending Updates Complete");

In the callback for each function I set the variable to true right before returning so the main thread can continue. But even doing it this way all the API calls except OnSendPrivateUpdateDone are getting called and my application just hangs in the loop waiting for the complete variable to be set unless I use a breakpoint on the callback or even just set a breakpoint right before warpClient.SendPrivateUpdate(). Any idea why this could be happening?
Alright so after TONS of trial and error I've found a solution. Basically what I've found is that for some reason the first time I call SendPrivateUpdate right after connecting and initializing the AppWarp connection it never gets the callback, but I also can't simply call it twice because I always seem to get a Network Error response code BUT if I call it once, then wait for 200ms like this:

myMutex.WaitOne();
await Task.Run(() =>
    {
        myMutex.WaitOne(200);
    });                               
myMutex.ReleaseMutex();

 and then call it again it with the exact same parameters it works fine and I only get 1 callback.

As to why this is happening I am not sure. It might have something to do with another issue it seems I've found: my connection to AppWarp is constantly disconnecting and then recovering using warpClient.RecoverConnection() even though my internet is perfectly stable and connected.

These bugs are most likely due to Windows Phone 8.1 and the AppWarp WinRT SDK both being brand new. Hopefully they get fixed soon though.
Okay well my previous solution no longer seems to be working today. But now even if I set a breakpoint on the callback it always returns error code 2 RESOURCE_NOT_FOUND for some reason. Am I not supposed to do connect() and then sendPrivateUpdate() in 1 button click right after each other? Because that is what my code currently does and I've noticed if I separate them out with first a login button that only connects and then another button that does the sendPrivateUpdate it seems to work.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...