-1

I have modified the Xamarin/Azure TODO example. But the code is stuck in

IMobileServiceTable.ToListAsync()

This is my IO class:

class DataIO
{
    BackgroundWorker DatabaseWorker = new BackgroundWorker();
    IMobileServiceTable<UserPosition> PositionTable;
    MobileServiceClient client;


    public DataIO()
    {
        Init();
    }

    public void Init()
    {
        client = new MobileServiceClient(Constants.ApplicationURL);
        PositionTable = client.GetTable<UserPosition>();
    }


    async void AddEntry(UserPosition entry)
    {
        await PositionTable.InsertAsync(entry);
    }

    public async Task<List<UserPosition>> GetEntries()
    {


        List<UserPosition> Entries = await PositionTable.ToListAsync();

        return Entries;
    }

    public async void DeleteEntry(UserPosition entry)
    {
        await PositionTable.DeleteAsync(entry);
    }

    public async void AddToDatabase(UserPosition item)
    {
        await PositionTable.InsertAsync(item);
    }
}

The debugger dosen't neither step over it nor throws an error. How to handle that?

In an earlier call, there wasn't any problem.

EDIT: I've rewritten the GetEntries() method to:

    public async Task<List<UserPosition>> GetEntries()
    {

        Task<List<UserPosition>> task = PositionTable.ToListAsync();


        List<UserPosition> entries = await task;

        return entries;
    }

according to this example. But the debugger just stays in the line

Task<List<UserPosition>> task = PositionTable.ToListAsync();
Christoph
  • 542
  • 4
  • 24
  • How have you modified the TODO example? If it is stuck, it sounds a lot like a deadlock scenario. Could you maybe try adding `ConfigureAwait(false)` to your async calls? Also please add more details about what you are doing and how you are calling this method. – Cheesebaron Aug 01 '17 at 10:02
  • I added my created class. The online table has entries (I added them before). But now I don't get data from azure anymore. List Entries = await PositionTable.ToListAsync().ConfigureAwait(false); doesn't change anything... – Christoph Aug 01 '17 at 10:07
  • 2
    Yeah, you are doing it wrong. Read up on how to use `async` and `await` keywords. – Cheesebaron Aug 01 '17 at 10:11
  • @Christoph, Apart from the other mistakes in the that class, how is the `GetEntries()` being called? Most likely you are mixing blocking and async code – Nkosi Aug 01 '17 at 10:19
  • I'm calling it in an async method with "Entries = await IOController.GetEntries();". Sorry I don't get the mistake with async and await :-( – Christoph Aug 01 '17 at 10:45
  • 1
    @Christoph if it is staying on that line it appears to be a deadlock. Something higher up the call stack is cause that line to block. – Nkosi Aug 01 '17 at 10:58

1 Answers1

0

AFAIK, IMobileServiceTable.ToListAsync() would send the request as follows for retrieving the result:

Get https://<your-app-name>.azurewebsites.net/tables/UserPosition

enter image description here

I would recommend you using Fiddler to collect the network traces when calling IMobileServiceTable.ToListAsync(). Also, you could access the table endpoint from your mobile app via the browser to make sure your mobile app could work as expected. Additionally, here is a great tutorial about Handling Data in Mobile Clients, you could refer to it.

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35