Hack Forums
[.NET] Duplicates with multithreading - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Duplicates with multithreading (/showthread.php?tid=5699256)



Duplicates with multithreading - SIM-3327349 - Aug 20, 2017

My code is still makes duplicates but I really don't know why.
Here is my code:
Spoiler (Click to View)

Here is screenshot of duplicates:
Spoiler (Click to View)

I found that this is working:
Spoiler (Click to View)

But this code is too long and I don't like it. I have many functions in my project and using this way for solving that problem is bad.

Please is anyone here, who can help me with that?
Thank you all in advance for help


* - +Haze - Aug 20, 2017

Why would it not make duplicates? You've done nothing to remove duplicates?


* - SIM-3327349 - Aug 20, 2017

(Aug 20, 2017 01:22 PM)+Haze Wrote:  Why would it not make duplicates? You've done nothing to remove duplicates?

There are no duplicates in rtbAccounts so there should not be any duplicates


* - WhyWork - Aug 20, 2017

Count the amount of accounts before spawning threads. If that's not the case then idk


* - SIM-3327349 - Aug 20, 2017

(Aug 20, 2017 02:03 PM)WhyWork Wrote:  Count the amount of accounts before spawning threads. If that's not the case then idk

Amount of accounts is correct..


* - +Haze - Aug 20, 2017

(Aug 20, 2017 01:23 PM)_Grow_ Wrote:  There are no duplicates in rtbAccounts so there should not be any duplicates

My guess is that since you're using multiple threads, you do not lock access to the rtbAccounts control, this means that multiple threads can access the rtb at once. So look into thread locking/thread syncronisation I believe it's called.

https://www.dotnetperls.com/synclock-vbnet
So you'd want to synclock rtbAccounts
Try that and let me know how it goes


* - SIM-3327349 - Aug 20, 2017

(Aug 20, 2017 02:24 PM)+Haze Wrote:  My guess is that since you're using multiple threads, you do not lock access to the rtbAccounts control, this means that multiple threads can access the rtb at once. So look into thread locking/thread syncronisation I believe it's called.

https://www.dotnetperls.com/synclock-vbnet
So you'd want to synclock rtbAccounts
Try that and let me know how it goes

It should help, but it didn't.. I tried SyncLock it almost everywhere, but without success.


That's weird. This code is working without problem https://pastebin.com/xUfTpmEv