GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Feb-2009, 14:47
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 761
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Using lock() with ArrayList


Hello experts. I am trying to lock a portion of my code where I have 2 ArrayList objects and need to transfer elements from one to the other. I am having a problem in that after I leave the lock() block, the elements in one of my arrays have vanished. Like so:

C-SHARP / C# Code:
ArrayList list1 = new ArrayList();
ArrayList list2 = new ArrayList();
Object mylock = new Object();
//....
lock(mylock)
{
  for(int i=0;i<list1.Count;++i)
  {
    list2.Add( list1[0] );
    list1.RemoveAt( 0 );
  }
   // Here, list2 has elements
}
// Here, list2 does not have elements
  #2  
Old 11-Feb-2009, 15:10
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 761
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Using lock() with ArrayList


My apologies. There was not a problem. It just appeared as though there was.
  #3  
Old 06-Apr-2009, 06:06
erniegerdie erniegerdie is offline
Awaiting Email Confirmation
 
Join Date: Feb 2004
Location: England
Posts: 93
erniegerdie has a spectacular aura abouterniegerdie has a spectacular aura about

Re: Using lock() with ArrayList


One point to note, you should really have your object as a readonly object, so that it cannot be changed whilst in the lock()

readonly Object mylock = new Object();
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Opperations on objects in ArrayList 05131013 Java Forum 1 25-Apr-2008 13:14
How do I lock the hardware buttons of Pocket PC in Dot net compact framework 2.0 Anil Darandale .NET Forum 0 14-Feb-2008 00:21
Lock Folder Without Any Software nsnraju Computer Software Forum - Windows 0 28-Sep-2007 01:18
Permission denied: ap_proxy: couldn't release the lock com2com Apache Web Server Forum 0 25-Mar-2006 10:23
Simple file lock works on unices, not on Windows QED C++ Forum 1 03-Feb-2005 07:25

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 10:35.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.