0

I have a function that constantly needs to check if there is work to do and it goes about in the following fashion:

Pseudocode:

Class SeperateThread{
    function Start(){
        DoWork();
    }
    function DoWork(){
        New DBContext;
        DBContext.GetWorkFromTables();
        Perform work in Extra Seperate Threads if there is work to do...
        NotifyWhenTasksAreFinished();
    }
    NotifyWhenTasksAreFinished(){
        (Loop)Check if tasks are finished in seperate thread 
        If Tasks are finished
        Break loop, wait a few seconds and....
        DoWork();
    }
}

I'm using SQLITE and getting a stack overflow in SQLITE.interop.dll

The only place where SQLITE work is done is with DBContext.GetWorkFromTables().

All this works fine for a few hours... after a few hours... APPCRASH with stack overflow inside sqlite.interop.dll.

Can anyone explain what's the reason for this and perhaps a workaround? I suspect the recursive function has something to do with it...

Could it be that the DBContext is not being disposed automatically and maybe this is the cause?

I'm using telerik Data Access as ORM but it kinda works like Entity Framework.

jarlh
  • 42,561
  • 8
  • 45
  • 63
user1841243
  • 1,663
  • 2
  • 19
  • 35
  • 4
    `DoWork` calls `NotifyWhenTasksAreFinished` which calls `DoWork`... This is most likely not related to SQLite. The likely reason why SQLite is the one that seems to be the culprit is that a stack overflow exception is like filling your glass with water. It isn't necessarily the last drop you put into the glass that you consider the reason for the overflow, it's the 10 billion drops you put in there before it. – Lasse V. Karlsen Sep 14 '15 at 07:55
  • Do you believe the recursiveness could be the cause? Is this in general wrong to perform infinantly or is it because some objects may not be disposed? If it is wrong, what workaround would be suggested? Thanks for your reponse. – user1841243 Sep 14 '15 at 08:23

1 Answers1

2

As @Lasse explains in their comment, infinite recursion will fill up your stack and cause the exception you get.

The fix is very easy: remove the recursion.

void Start()
{
    while (true)
    {
        DoWork();
        NotifyWhenTasksAreFinished();
    }
}
Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272