Solved

Synclock a part of a 2 dimensional array?

Posted on 2006-06-12
5
257 Views
Last Modified: 2010-04-23
How can I synclock a part of a 2 dimensional array?

Dim objThing(1000,1000) as String

Synclock objThing(800,800)

End Synclock

This way I can access only one part while the rest of the object can be accessed by other threads at the same time?

0
Comment
Question by:Hepen
  • 3
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 16883651
Yes, by this way you can lock one array member.
0
 

Author Comment

by:Hepen
ID: 16883652
i tried but it wouldn't let me ... can u show me the code
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16883658
However, this doesn't prevent other thread from working with whole objThing array, like:
objThing = Nothing

If your code doesn't do this, it is OK.
0
 

Author Comment

by:Hepen
ID: 16883661
Let me give u points for this question i'm gonna ask another one i made a small mistake.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16883671
Oops, there is restriction:
You cannot change the value of lockobject while executing a SyncLock block. The mechanism requires that the lock object remain unchanged.

Since string is immutable object, this code will not work. This can work with other classes, with one additional restruction: lockobject cannot be Nothing. For example:

Dim objThing(1000,1000) as MyClass
' initialize all objThing members to New MyClass

Synclock objThing(800,800)
  ' ...
End Synclock

So, this way can be used with initialized array of mutable instances. In your case this will not work, you need to lock the whole array.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question