multithreading - VB.NET Compare each item in collection to every other item in collection - Threading -
this first time posting please accept apologies if im not doing right , please feel free correct me formatting or posting guidelines. doing in vb.net .net framework 4.5.2.
i have large collection called gboard in class.
private gboard collection
it contains 2000 instances of class.
what trying achieve each item in class, want @ each other item in class , update first item based on variables in second.
currently have following code:
in main class:
private gboard new collection ' populated elsewhere in code private sub checksurroundings() integer = 1 (xboxes) j integer = 1 (yboxes) x = 1 integer (xboxes) y = 1 integer (yboxes) tile(new point(i, j)).checkdistance(tile(new point(x, y))) next y next x next j next end sub private function tile(byval apoint point) clstile return gboard.item("r" & apoint.y & "c" & apoint.x) end function
in clstile have following (as other items):
private function surroundingterrain(byval ater string) clsterrain return mysurroundings.item(ater) ' small collection (6 items of clsterrain type) end function public sub checkdistance(byref atile clstile) surroundingterrain(atile.terrain).checkdistance(calcdistance(location, atile.location)) end sub private function calcdistance(byval mypoint point, byval apoint point) double dim myreturn double = 0 dim xdiff integer = 0 dim ydiff integer = 0 dim tdiff integer = 0 xdiff = math.abs(mypoint.x - apoint.x) ydiff = math.abs(mypoint.y - apoint.y) tdiff = xdiff + ydiff myreturn = (minint(xdiff, ydiff) * 1.4) + (tdiff - minint(xdiff, ydiff)) return myreturn end function private function minint(byval integer, byval b integer) integer dim myreturn integer = if b < myreturn myreturn = b end if return myreturn end function
in clsterrain have following sub called:
public sub checkdistance(byval adist double) if adist < distance distance = adist end if end sub
this runs , works file can guess runs slow... have been trying work out how make run faster , looked threading/tasks doesnt seem work. there no errors objects don't appear update correctly (or @ all). code tried was:
in main class:
private sub checksurroundings() dim tasks new list(of task) dim ptile clstile each ptile in gboard tasks.add(task.run(sub() tiletocheck(ptile))) next task.waitall(tasks.toarray()) end sub private sub tiletocheck(byref atile clstile) x integer = 1 (xboxes) y integer = 1 (yboxes) atile.checkdistance(tile(new point(x, y))) next y next x end sub
does have suggestions or ideas how work?
sorry headaches or facepalms caused...