You are writing a method that returns an ArrayList named al. You need to ensure that changes to the ArrayList are performed in a thread-safe manner. Which code segment should you use?

You are writing a method that returns an ArrayList named al. You need to ensure that changes to
the ArrayList are performed in a thread-safe manner. Which code segment should you use?

A. Dim al As ArrayList = New ArrayList()SyncLock al.SyncRoot
    Return alEnd SyncLock

B. Dim al As ArrayList = New ArrayList()SyncLock al.SyncRoot.GetType()
    Return alEnd SyncLock

C. Dim al As ArrayList = New ArrayList()Monitor.Enter(al)Monitor.Exit(al)Return al

D. Dim al As ArrayList = New ArrayList()Dim sync_al as ArrayList =
    ArrayList.Synchronized(al)Return sync_al


Answer: D 




No comments:

Post a Comment