Solved

Synclock a part of a 2 dimensional array?

Posted on 2006-06-12
5
252 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now