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?
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?