Solved

Synclock a part of a 2 dimensional array?

Posted on 2006-06-12
5
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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