Text Stream Exit

FYI: Those MsgBox calls should not be in any code that runs in a thread. Bad Things will happen if they are reached.

I’m surprised that compiles.

They are only in there because of the problems I have been having with this. I can upload a file or you can just point it at a folder with a few PDFs in it.

What do I do with the RAM disk button?

Select a drive with it. It will not matter for the initial database portion. In the actual program, there is a RAM disk installed where some processing occurs in the latter part of the program.

I’m a little confused by your code. You start a thread to handle the file processing, but immediately declare the process “done” without waiting for the thread to finish. The code that handles the “after” processing should be moved to the Timer, and that code should check the Thread state first, no?

I think what’s happening is, your trace is exiting the thread when it switches contexts after, say, 5 iterations of the loop, and you thought that meant it was done. But if you put a breakpoint directly under the For statement in your loop and just keep hitting “run”, you’ll see that most of your files are processed after the dialog comes up.

Now I am confused. Where am I declaring the process “done?” The code that calls the processing is this:

[code] If FromFile.Value = False Then
App.RecrsFldrs = New clsRecurseFolders
'Dim RecrsFldrs As New clsRecurseFolders

'2_0 Update
'RecrsFldrs.Priority = 10
App.RecrsFldrs.Run
'RecrsFldrs.Run

Else
App.FrList = New clsFromList

'2_0 Update
'FrList.Priority = 10
App.FrList.Run

End If
[/code]

Nothing else is happening while one of these two threads is running. There is a spinning progress wheel, but that is it. I tuned that off and it did not change the result.

What dialog are you thinking is coming up? Neither of the threads calls a dialog box. The message boxes are only called on an error and there is never one raised.

I am not trying to be argumentative, I am just not understanding what you are referring to.

Sorry, I wasn’t being literal. Let me explain with code.

The button runs this code:

  If FromFile.Value = False Then
    App.RecrsFldrs = New clsRecurseFolders
    'Dim RecrsFldrs As New clsRecurseFolders
    
    '2_0 Update
    'RecrsFldrs.Priority = 10
    App.RecrsFldrs.Run
    'RecrsFldrs.Run
    
  Else
  …

That starts RecrsFldrs, so now that Thread is running. But then immediately below that appears

  '2_0 Update
  ProgressWheel1.Visible = False
  
  '2_0 Update
  rs =App.FileList.SQLSelect("SELECT PrimeKey, * FROM Files")
  App.TotalFiles = rs.RecordCount
  rs.Close

… // More housekeeping

And further down

  msg = MsgBox("File Processing Complete" + chr(10) + Chr(13) + chr(10) + Chr(13) _
  + "Files Processed: " + Format(App.TotalFiles, "###,###,###") + chr(10) + Chr(13) _
  + chr(10) + Chr(13) + "Elapsed Time: " + strElapTm)

In other words, the housekeeping is done and MsgBox appears while the Thread is still running, and never do you check to see if the Thread is actually finished.

What’s happening when you start the Thread is that it switches to to it and loops a few times. But because Threads are cooperative, Xojo decides to switch back to the main thread (the code within the pushbutton) and finish running that code, including that final MsgBox, but the Thread isn’t done by the time that box appears. After you dismiss the box, the Thread resumes and finishes its loops.

Thanks for your patience. You are correct. I now see that in a fit of zealous refactoring I removed the code that caused the main thread to wait. These little programs are a part-time adjunct to my regular job. Obviously, I need to spend a bit more time keeping sharp on this. Thanks again.

If you are using code that makes the main thread wait, you shouldn’t be using a Thread at all as there is no point. Instead, since you have a Timer set up, have the Timer check the status of the Thread and, when it’s no longer Running, execute the final code.

Glad I could help.