I have a service application that has been running fine. I added code to use a private thread and a private timer into a sub class of tcpSocket and now my app is crashing. Not a debugger crash but a windows crash, so I really have no idea where the problem is in the code. I’m unsure if what I am doing is bad practice or not. I was hoping someone on here could tell me if what I am doing is causing a system issue leading to a windows crash or if I should report this as a bug with my crash dump.
I have a sub class of TCPSocket in a service app. I have a private thread property and private thread handler method. I have a private timer property and private timer handler method.
In the DataAvailable event I am initializing them both like this when all of my data has come into the socket:
[code] tmrParse = New Xojo.Core.Timer
tmrParse.Period = 700
tmrParse.Mode = Xojo.Core.Timer.Modes.Multiple
AddHandler tmrParse.Action, AddressOf TimerAction
ThdResponse = New Thread
AddHandler ThdResponse.Run, AddressOf ThdResponse_Run
ThdResponse.Run[/code]
So each time a connection is made a new thread and timer are initialized. I’m not sure if this over time is causing the app to crash. It runs for a few minutes each time and then I get a windows crash.
So I decided to try to remove the handler after each message was sent back to the client to see if that helps but I can’t seem to remove the timer handler either using the exact code from the dev site it says, this item does not exist on the Sender.Mode line?
' Stop Timer and Remove the handler
Sender.Mode = Xojo.Core.Timer.Mode.Off
RemoveHandler tmrParse.Action, AddressOf TimerAction
I’m not sure of the sender line for the thread if there is an equivalent or not. I tried this:
' Remove the handler
Sender.Mode = ThdResponse.Kill // This line doesn't compile, maybe I don't need this line to remove the thread handler
RemoveHandler ThdResponse.Run, AddressOf ThdResponse_Run
Am I initializing these handlers wrong? I know if it’s a Desktop app you initialize them in Open event. Of course there is no Open event in the service app, I tried to initialize them in run using a public method in the TCPSocket sub class but I kept getting a NilObjectException.
Ugh rough day, any advice please? Thanks…