none
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll?

    Question

  • Hi I am New To Vb.net . I am Using Visual Studio 2008 Express edition (.NET Framework 3.5) ...  I got this Error when Using A recursive Call To a Function .. I have 3 Background Workers Which Select Data From Database With Status =0 , Take The file Name And File Path Asssosiated With That record, and Then Copy it to other place and on successful completion update the status  to 2 otherwise to 3 . and again searech for other record having Status 0 and so on ..
    i made a method for selection of record from database every worker call this function . Now I have a check when dataset is filled i checked is there any row ? if yes then it do the rest of work otherwise agin call it self to search for the record..... RECURSION...... 
    In Case of records with status zero , It works Fine But in Case of no records Which have status zero it recursively calls itself For approx 1.5 mints and then throws The Exception That " System.StackOverflowException occured in mscorlib.dll at line "DataAdapter.Fill(Dataset,Table)" . I have no Idea what to do with this ..
    Eventhough I have Encloesd It in Try...Catch Blocks but It didnt Cath It .. I serached The Internet and msdn social help for it and i found that it occurs most with infiniteloop or Infinite Recursive calls. i know it is due to my recursive call to the SelectData Function But i have no option without it so please help me out  . Help From Everyone Is appriciated in advance..

    And One thing more that this project i mean the exe of this project is concurrently runs with another project Which add data to the databse about Filename Filepath and status =0 for Fresh entry..

    Hope This will Clear what i am trying to explain..

    Thanks IN Advance

    Muhammad BILAL
    Wednesday, April 01, 2009 3:48 PM

Answers

  • The most common cause of this error is an "infinite loop" condition in the code; the fact that you've designed a "recursive" code routine pretty much guarentees that this is the case.

    You should always post a short example of the code in question - even if you have to create a simplified version of your code to do so.  Otherwise any answer is likely to only be a rough guess...

    In this case, the design sounds overly complex - You may have gotten carried away with your multithreading...

    Questions: 

    Does your DataTable get cleared each time before it is filled again? 

    Do you need three background workers?  And are you SyncLocking the datatable so that only one worker can fill it at a time?

    Do you have a pause in the background worker's scanning loop?  There would be no need to scan on every iteration of the loop - in fact there should be no reason to check for new records more than once every few seconds - so put the loop to sleep with System.Threading.Sleep() or use a datetime variable to determine how often to scan for new records.

    If you need your two application to share data faster than every few seconds, then you should do away with the intermediate database layer and switch to direct communications between the two applications (Remoting or IP Sockets are two common methods).  The intermediate database would only be suitable for slow periodic exchanges of data between applications.  Highspeed exchanges need to be done directly.

    So it sounds like a design issue, but we'd need more information to really say for sure.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    Wednesday, April 01, 2009 4:20 PM

All replies

  • The most common cause of this error is an "infinite loop" condition in the code; the fact that you've designed a "recursive" code routine pretty much guarentees that this is the case.

    You should always post a short example of the code in question - even if you have to create a simplified version of your code to do so.  Otherwise any answer is likely to only be a rough guess...

    In this case, the design sounds overly complex - You may have gotten carried away with your multithreading...

    Questions: 

    Does your DataTable get cleared each time before it is filled again? 

    Do you need three background workers?  And are you SyncLocking the datatable so that only one worker can fill it at a time?

    Do you have a pause in the background worker's scanning loop?  There would be no need to scan on every iteration of the loop - in fact there should be no reason to check for new records more than once every few seconds - so put the loop to sleep with System.Threading.Sleep() or use a datetime variable to determine how often to scan for new records.

    If you need your two application to share data faster than every few seconds, then you should do away with the intermediate database layer and switch to direct communications between the two applications (Remoting or IP Sockets are two common methods).  The intermediate database would only be suitable for slow periodic exchanges of data between applications.  Highspeed exchanges need to be done directly.

    So it sounds like a design issue, but we'd need more information to really say for sure.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
    Wednesday, April 01, 2009 4:20 PM
  • The most common cause of this error is an "infinite loop" condition in the code; the fact that you've designed a "recursive" code routine pretty much guarentees that this is the case.

    You should always post a short example of the code in question - even if you have to create a simplified version of your code to do so.  Otherwise any answer is likely to only be a rough guess...

    In this case, the design sounds overly complex - You may have gotten carried away with your multithreading...

    Questions: 

    Does your DataTable get cleared each time before it is filled again? 

    Do you need three background workers?  And are you SyncLocking the datatable so that only one worker can fill it at a time?

    Do you have a pause in the background worker's scanning loop?  There would be no need to scan on every iteration of the loop - in fact there should be no reason to check for new records more than once every few seconds - so put the loop to sleep with System.Threading.Sleep() or use a datetime variable to determine how often to scan for new records.

    If you need your two application to share data faster than every few seconds, then you should do away with the intermediate database layer and switch to direct communications between the two applications (Remoting or IP Sockets are two common methods).  The intermediate database would only be suitable for slow periodic exchanges of data between applications.  Highspeed exchanges need to be done directly.

    So it sounds like a design issue, but we'd need more information to really say for sure.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Thank You Reed ..
    The system.threading.thread.sleep() solved the problem .. 

    Muhammad Bilal 
    Sunday, May 10, 2009 8:16 PM