J
j3ko
Hi, I'm trying to start a thread that constantly iterates through an
arraylist of items that the main thread adds and removes from...how
would I accomplish this?
Here's the gist of what I have: (can anybody give me pointers on what
i'm doing wrong?)
Class SecondThread
aList as new arraylist
innerthread as new thread(addressof task)
public sub task()
while true
synclock aList.syncroot
for i as integer = 0 to aList.count-1
' do something
end for
end synclock
innerthread.sleep(10000)
end while
end sub
public sub start()
innerthread.start()
end sub
public sub add(item)
synclock aList.syncroot
aList.add(item)
end synclock
end sub
public sub remove(item)
synclock aList.syncroot
aList.remove(item)
end synclock
end sub
end class
my main thread calls start when I load and calls add and remove
periodically...It seems to add just fine...but a call to remove does
nothing :\
arraylist of items that the main thread adds and removes from...how
would I accomplish this?
Here's the gist of what I have: (can anybody give me pointers on what
i'm doing wrong?)
Class SecondThread
aList as new arraylist
innerthread as new thread(addressof task)
public sub task()
while true
synclock aList.syncroot
for i as integer = 0 to aList.count-1
' do something
end for
end synclock
innerthread.sleep(10000)
end while
end sub
public sub start()
innerthread.start()
end sub
public sub add(item)
synclock aList.syncroot
aList.add(item)
end synclock
end sub
public sub remove(item)
synclock aList.syncroot
aList.remove(item)
end synclock
end sub
end class
my main thread calls start when I load and calls add and remove
periodically...It seems to add just fine...but a call to remove does
nothing :\