VB.net Multi-threading problem.

Hi everyone!

I have built a web spider that is using Lucene to index the information.

However, when I implemented multi-threading, several threads are trying to write into the index at the same time, this generates an exception.

I assume the same happens with other cases, such as opening a file for writing with a thread, and then trying to access the file with another thread.

Could somebody provide some tips (code preferably) to avoid this thread conflicts or make the threads "wait" until the others have finished their job?

Thanks a lot!
glopezz
glopezzAsked:
Who is Participating?
 
solublefishConnect With a Mentor Commented:
Multithreading is a very deep topic. If you're using .NET collections, the framework can do a lot of work for you. Learn about the 'lock' keyword and the .Syncronized and .SyncRoot methods of most .NET collection classes:

All these have code examples:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfLockStatement.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsarraylistclasssynchronizedtopic1.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsarraylistclasssyncroottopic.asp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.