-1

This is a fairly simple question, but I couldn't find an answer on Google, so here I am.

I am trying to access a thread once it has been created within Visual Basic .NET.

Dim T As New Thread(New ThreadStart(AddressOf RemoteThread))
T.Name = "Helloworld"
T.Start()

My question is, how do I access the thread "Helloworld" once it is started using the above code?

user1837725
  • 493
  • 1
  • 5
  • 9
  • What do you mean? You are already accessing the thread, it's the `T` variable – Panagiotis Kanavos May 20 '15 at 14:29
  • Can you describe what you want to do with the Thread? – Spevy May 20 '15 at 14:30
  • I will have a lot of threads executed and they will be named sequentially, like "thread1", "thread2", etc. I want to be able to update variables on a specific thread from my main application. – user1837725 May 20 '15 at 14:32
  • Your question is very generic. See http://stackoverflow.com/questions/1360533/how-to-share-data-between-different-threads-in-c-sharp-using-aop for one possible solution. – Spevy May 20 '15 at 14:46
  • @user1837725 Threads aren't containers for variables. They represent the execution of a method. In any case *you can't* access a method's variables from outside the method. I think you should start with a tutorial on multi-threading. – Panagiotis Kanavos May 20 '15 at 14:56
  • Perhaps he's creating 10 threads, and in some cases he may want to abort all of them. He needs a way to be able to call T.abort(). – Tony Hinkle May 20 '15 at 15:03

1 Answers1

0

To access multiple threads that you've created, add them to an array or arraylist. Then you can simply loop through the array or whatever to get access to them. Example below to call the abort method on all of the threads in the ThreadArray array.

For Each t as System.Threading.Thread in ThreadArray t.abort() Next

Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35
  • I'm pretty sure there are better ways to do this, but this might help get you going until someone else provides a better answer. – Tony Hinkle May 20 '15 at 15:06