Nope, “archive” is a method. I try to keep my messes as small as possible. One thread is more than enough complexity. Also, the problem occurs only for a very low number of users.
Is it possible that Archiver is running more than 1 time and that another instance of Archiver is calling Finish while the next Archiver is still working?
Maybe, instead of running Finish from within ArchiveThread you could start a Timer from within ArchiveThread and this Timer will run in Multiple Mode checking if any Archive is running before starting a Finish Thread?
Archiver is running only once. At the end of archiving there is a notification back to the model class. This class can check if the archive thread is still running or not and then initiate the diagnosis.
But I’d still like to understand what the §$%& is happening here.
I would start checking if the Notification System is working reliable in all cases and then if the Check for a running Archive Thread could fail in any case.
Maybe it’s a thread owned by SQLite. Do the headings in the crash log say that these happen in different threads?
Does it happen every time? Only with large db’s or specific SQLite version?
Just guessing but maybe the SQLite is still finishing writing and this writing happens in another thread?
Also make sure the button can only be clicked once so the thread can’t be fired multiple times.
@Marco: I’m hoping for guesses because the code is very complicated.
The threads both access Valentina, which makes the crash. Yes, it’s different threads.
Doesn’t happen every time. Just a very low number of users have had this problem. Don’t know about the size of the database.
According to my code archiving should be done before diagnosing.
The button can be clicked only once. Checked again this morning.
@Sascha: at the moment the notification doesn’t play a role. It’s strict doing thing 1 and then thing 2 in one thread. Thing 2 creates another thread. Would that make a difference?
[quote]It’s strict doing thing 1 and then thing 2 in one thread.
Thing 2 creates another thread.
Would that make a difference?[/quote]
Although you said you only have one thread going at at time, the above suggests the opposite.
Is this what is happening…?
Launch thread A
Thing 1 happens
Thing2 happens and launches another thread B … there are now two threads?
Thing2 ends… perhaps 2 threads still going
Thread A ends?
Thread B ends? – or vice versa
@Jeff: let me try to summarize (it’s a good portion of a >50k app):
Thing 1 adds data to a database. No more threads.
Thing 2 does a diagnosis of said database. This creates a second thread, which is called here and waits for the calling function:
dim theDiagnoser as new DiagnoseThread(theDatabase)
theDiagnoser.Run
while not DiagnoseFinished
app.SleepCurrentThread 1000
wend
The diagnosis thread sends a notification to the calling function and sets DiagnoseFinished to true. The more I think about the problem the more I think that this is the root cause.