There are a lot of ways - some of these may be interesting to you:
Counting Lines in a String[
^]
Threads have a void signature because when they come to an end they are killed, and that releases the stack memory they were assigned. Since the stack is no longer there, there is no way to return a value via the usual
return
keyword!
Instead, your thread must communicate it's result back to the calling thread in a different way, and that will depend on how you start your threads.
If you use a BackgroundWorker class, then that helps you out a lot - it provides an Event the main thread had handle when the thread ends which provides a Result property in the EventArgs that teh main thread can read:
BackgroundWorker Class (System.ComponentModel) | Microsoft Docs[
^] - the link includes sample code.