0

I've been testing my Xamarin.Forms on iOS and ran into an error with the WithChildren methods in SQLiteNetExtensions.

My code seems to get stuck in lines containing GetAllWithChildren and GetWithChildren, as if there's some deadlock issue in the library. I'd like to believe this is wrong, since this works well in Android and the problem is only in iOS. However, it's important to note that this doesn't happen every time I start the app, only once every few runs...

Code Example:

try
{
    return DB.GetAllWithChildren<T>().ToArray();
}
catch (Exception ex)
{
    return null;
}

DB is of type SQLiteConnection and has an instance.

Ideas on what's going on or help on solving this will be very appreciated.

The issue on Github: https://github.com/media-tools/sqlite-net-extensions/issues/5

E. Epstein
  • 739
  • 2
  • 11
  • 26
  • Deadlock often indicates misuse of UI thread. Try calling in a background thread, not the UI thread. Then whatever you need to run afterwards, do via an action callback or other mechanism. Read about c# managing MainThread (Ui thread) vs background work. async/await might also solve. – ToolmakerSteve Apr 25 '23 at 20:43
  • @ToolmakerSteve Do correct me if I'm wrong, but from what I know, it may be true that deadlock happening on the UI thread will make the app stuck, however running the operation in an async/await block will simply look like the app is not loading its resources. Therefore the problem won't really be solved in this case. – E. Epstein Apr 26 '23 at 08:44
  • I don’t understand the point you are making. App is stuck on a given line of code. IF what is happening is a UI thread deadlock, called code eventually *queues* an action to run on the UI thread “when it becomes available“, then waits for that queued code to finish. If your method is on UI thread (and did not “await” the called method), then that queued code never gets a chance to run. So the call never returns. Perhaps the library could be written differently, but you don’t have control over that, so change how you use it. Either get off UI thread, or “await”. – ToolmakerSteve Apr 29 '23 at 23:19

0 Answers0