Hi, I am new t console applications and I’m trying to get my head around how they execute. For instance I have a console app which within it’s Run event instantiates a class who’s super is thread and runs it.
What happens once my thread begins running but my console app reaches the end of the Run event. Does the thread continue to run to completion or is it killed due to the completion of the event which instantiated it?
You’ll need to put an events loop at the end of your run event handler to keep the app alive.
Thanks Wayne, just thought of that and it seemed to fix the issue, i’ve looped until the thread state <> running.
Is it the case then that the thread will be killed by the console run event completing?
Yes. Without an event loop the run event handler will end closing the application. Putting your thread run code directly into the run event would be the best solution unless you are using multiple threads.
I wondered if I should do that. I was being lazy really as I wrote the thread class for a GUI app so it was less work to pull it all in as a class with all its properties, methods and event defs. But I feel you are correct and it is going to be a lot easier to manage if its directly in the run event. Its just rather cumbersome too but I will have a look at doing as you suggest.
Override the Thread.Run method to add an optional parameter,
immediate as Boolean = False. If immediate, just run the code without calling
super.Run. That should be an easy refactor.
Am I right in thinking that console apps make use of multiple cores if I break my code up into a number of threads? Do I have to control this or is it low level?
no more so than a desktop app would - which is not at all
to use multiple cores you need to run multiple instances