I have a rather simple program that has one thread that does a bunch of work with a timer controlling it. Within the thread I have some Try Catch statements to catch any runtime or exception errors that occur but they never trigger. The problem is that I keep getting this strange runtime error dialog:
Any help on figuring out what this error means would be appreciated. I have been using Xojo for almost 20 years but have never seen one like this. The program will run for about 30 minutes then like clockwork this error comes up.
The last part of that error, a new thread was being requested. Without seeing your code, or a simplified version it is going to be hard to diagnose. Is your timer creating new threads? Is it runaway - ie: creating new threads each time until all resources are exhausted? Maybe whatever the timer is starting (method) isn’t completing before the timer fires again creating another method process.
So what the timer does basically is wait for a button to appear (this is a bot btw) and when it does it launches a new thread. Now before it launches the thread it turns itself off with ModeOff and also has a variable to indicate that the thread is running. When the thread finishes it deflags that variable and also turns the timer back on to ModeMultiple. I had to use that thread running on off flag as for some reason Xojo gives me an error that the thread does not exist when I try to use Thread.State to determine if its running or not. No idea why as I am creating a new thread with no problems. Never seen Xojo do that before either.
This works:
if BotsTurn = TRUE then
me.Mode = Timer.ModeOff
app.ThreadRunning = TRUE
Dim NewBot as new BotThread()
NewBot.Run
end
But if I do this:
if BotThread.State <> 4 then Return
I get a “this item does not exist” error. I must be doing something wrong on this but have been unable to figure that out either.
Ah right. Ok well it works with the app.ThreadRunning flag so no worries there (although I really do not even need it). I still got that dialog twice last night. My basic thread run event looks like this:
[code]Try
//do a bunch of stuff here
me.Sleep(1000)
Catch e As RuntimeException
DumpExceptions(1)
Catch e as NilObjectException
DumpExceptions(2)
End Try
Is that really true? Because i start Timers in Windows all the Time from Threads, but only from Threads which are within the Scope of the targetet Window.
AFAIK, Timers are not Part of the UI and because of this, we can start + stop them from within a Thread?
I get a thread accessing UI exception here if I use michaels code in the run event of the thread
Sometimes
IF the windows happens to close between starting the thread and the code that eventually sets the mode then you get a thread accessing UI exception
If it doesnt - you dont
All the above code is about it. The rest is just a bunch of if then statements and some calls to a xml-rpc server using the Chilkat plugin. I am hoping killing the timer mode statement will fix the problem. I will advise if that worked or not. I am hoping so!
I tried it again with no luck after removing the timer mode call. It still crashes after exactly 72 calls to the thread. Perhaps the threads are not killing themselves after they have been run? No idea how to figure this out…
a) Xojo has a runtime class (http://documentation.xojo.com/api/language/runtime.html) which has an object count. You can get more information about the existing objects.
b) You are on the dark side, right? In XCode you could use Instruments with Leak Check which shows every runaway byte. Are there similar tools for Windows?