Click here to Skip to main content
15,894,460 members
Home / Discussions / C#
   

C#

 
GeneralRe: When to use C# , when VC++ ? Pin
J. Dunlap16-Jun-03 19:17
J. Dunlap16-Jun-03 19:17 
GeneralRe: When to use C# , when VC++ ? Pin
Rocky Moore16-Jun-03 22:34
Rocky Moore16-Jun-03 22:34 
GeneralRe: When to use C# , when VC++ ? Pin
Meysam Mahfouzi10-Aug-03 4:20
Meysam Mahfouzi10-Aug-03 4:20 
GeneralRe: When to use C# , when VC++ ? Pin
Rocky Moore11-Aug-03 0:57
Rocky Moore11-Aug-03 0:57 
GeneralShowing a Form as a drop-down menu Pin
Patrick Bristow15-Jun-03 6:53
Patrick Bristow15-Jun-03 6:53 
GeneralRe: Showing a Form as a drop-down menu Pin
J. Dunlap15-Jun-03 7:32
J. Dunlap15-Jun-03 7:32 
GeneralRe: Showing a Form as a drop-down menu Pin
Patrick Bristow15-Jun-03 7:41
Patrick Bristow15-Jun-03 7:41 
GeneralRe: Showing a Form as a drop-down menu Pin
J. Dunlap15-Jun-03 8:14
J. Dunlap15-Jun-03 8:14 
GeneralRe: Showing a Form as a drop-down menu Pin
Patrick Bristow15-Jun-03 8:44
Patrick Bristow15-Jun-03 8:44 
GeneralRe: Showing a Form as a drop-down menu Pin
J. Dunlap15-Jun-03 9:15
J. Dunlap15-Jun-03 9:15 
GeneralRe: Showing a Form as a drop-down menu Pin
Patrick Bristow15-Jun-03 9:28
Patrick Bristow15-Jun-03 9:28 
GeneralRe: Showing a Form as a drop-down menu Pin
J. Dunlap15-Jun-03 10:45
J. Dunlap15-Jun-03 10:45 
GeneralI've got it! Pin
J. Dunlap15-Jun-03 11:27
J. Dunlap15-Jun-03 11:27 
GeneralRe: I've got it! Pin
Patrick Bristow15-Jun-03 11:35
Patrick Bristow15-Jun-03 11:35 
GeneralRe: I've got it! [UPDATED] Pin
J. Dunlap15-Jun-03 11:40
J. Dunlap15-Jun-03 11:40 
GeneralRe: SetWindowLong and SetWindowPos Pin
J. Dunlap15-Jun-03 13:35
J. Dunlap15-Jun-03 13:35 
GeneralRe: SetWindowLong and SetWindowPos Pin
J. Dunlap15-Jun-03 22:26
J. Dunlap15-Jun-03 22:26 
GeneralRe: SetWindowLong and SetWindowPos Pin
J. Dunlap16-Jun-03 8:02
J. Dunlap16-Jun-03 8:02 
GeneralRe: Showing a Form as a drop-down menu Pin
A.Wegierski15-Jun-03 22:54
A.Wegierski15-Jun-03 22:54 
GeneralRe: Showing a Form as a drop-down menu Pin
J. Dunlap16-Jun-03 7:47
J. Dunlap16-Jun-03 7:47 
GeneralArrayLists & multithreading... Pin
viperxp15-Jun-03 5:56
viperxp15-Jun-03 5:56 
GeneralRe: ArrayLists & multithreading... Pin
leppie15-Jun-03 6:44
leppie15-Jun-03 6:44 
GeneralRe: ArrayLists & multithreading... Pin
Arjan Einbu15-Jun-03 11:46
Arjan Einbu15-Jun-03 11:46 
GeneralRe: ArrayLists & multithreading... Pin
viperxp15-Jun-03 23:24
viperxp15-Jun-03 23:24 
GeneralRe: ArrayLists & multithreading... Pin
James T. Johnson16-Jun-03 0:10
James T. Johnson16-Jun-03 0:10 
viperxp wrote:
I ahve looked at both the Synchronized()

The Synchronized() method returns an instance of an ArrayList which takes care not to let only one operation run at a time.

The SyncRoot property returns an object which you can use to do your own locking (by using the lock keyword for instance).

ArrayList syncList = ArrayList.Synchronized(theList);
 
... 
 
// Let methods be called willy-nilly, 
// the synchronized wrapper will be automatically protected
And a second demo:

ArrayList theList = ...;
 
...
 
lock(theList.SyncRoot)
{
  // use 'theList' and be assured that only 
  // this thread is inside of this block
}
I prefer using lock, because it makes it very obvious that the code within is protected instead of trying to trace your steps through code to see whether you forgot to create the Synchronized wrapper.

The only advantage I can think of using the synchronized wrapper would be if you were performing lots of operations in a row where it didn't matter if other threads accessed the list in between those operations.

James

"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.