Unwanted Threading

curlydog

Well-known member
Joined
Jul 5, 2010
Messages
50
Programming Experience
Beginner
I'm writing a windows forms application for viewing forums.

I have a user, thread and post class. The user class contains an arraylist of threads (threads the user has created) and in turn the threads class contains an arraylist of posts (posts in the thread).

In order to get the threads and posts for a user I'm using code along the lines of
VB.NET:
for each t as thread in alThreads
    t.getPosts
next

The problem I'm having is that when this code is executed, all of the getPosts methods seem to run concurrently (one for each thread object), seemingly each in it's own thread. This causes an issue as the getPosts method involves navigating to a web page and reading it. I'm finding that the next thread is calling the getPosts method before the previous one has finished. This is causing issues at runtime.

How can I ensure that the program runs only in a single thread so that one thread object completes it's getPosts method, before the next one starts.
(sorry for the confusion with threads and threading)

Thanks
 
That code is not going to run in multiple threads by default. I can only assume that, somewhere in your code, you have used the type Thread meaning your forum thread but the compiler has interpreted it as a System.Threading.Thread. You need to make sure that you are always referring to the correct type.
 
Back
Top