From: NvrBst on
I've been playing around with a bunch of synchronization classes latly
but I can't seem to get the following one to work? When I do
"SynchronizedKeyedCollection<int,int> myDic = new
SynchronizedKeyedCollection<int,int>();" I get the error:

Cannot create an instance of the abstract class or interface
'System.Collections.Generic.SynchronizedKeyedCollection<int,int>'

There is also no intellisence for completing the "new ..." keyword
like other classes. Could someone give me a quick example on how to
use this class? (I see on MSDN it has a constructor, shouldn't I be
able to use it like I would a Dictionary<T,K>?)

NB

Note: I have .NET 3.5, and using VS2008 (Team System).
System.ServiceModel is referenced and IntelliSence is highlighting the
class like it can see it. I'm also able to use the
"SynchronizedCollection<int>" like I do a List<T>
From: Marc Gravell on
It is abstract, so if it has a constructor then it is proteted...

Basically, unless you provide your own concrete implementation of
this, you can't use it. The only concrete subclass (that I can see) is
System.ServiceModel.UriSchemeKeyedCollection.

Of course, I *still* don't believe they gain much ;-p

Marc
From: NvrBst on
On Feb 21, 8:57 pm, Marc Gravell <marc.grav...(a)gmail.com> wrote:
> It is abstract, so if it has a constructor then it is proteted...
>
> Basically, unless you provide your own concrete implementation of
> this, you can't use it. The only concrete subclass (that I can see) is
> System.ServiceModel.UriSchemeKeyedCollection.
>
> Of course, I *still* don't believe they gain much ;-p
>
> Marc


Ahh, your right. When I read "SychronizedCollection<T>" I thought it
would autolock at the lower levels to ensure no crashing and the such
(Good for quick, simple use of a thread safe collection). But now
when I read it again on MSDN "The SynchronizedCollection<(Of <(T>)>)
stores data in a List<(Of <(T>)>) container and provides an object
that can be set and used to synchronize access to the collection so
that it is thread-safe.". This means I have to lock manually (just
like I would with List<T>) before using it? Basically Identical to a
List<T> excpet it has a SyncLock object built inside?

That is almost useless, if I'm understanding it right :) If I'm
mistaken (and the collection does auto lock at lower levels), please
correct me :)

NB
From: Marc Gravell on
> Ahh, your right. When I read "SychronizedCollection<T>" I thought it
> would autolock at the lower levels to ensure no crashing and the such

It appears to lock for individual operations; but *generally* in my
experience you need to consider multiple operations as a transaction
for it to be useful (whether that is the duration of a foreach, or a
"contains/add" pair, etc).

But essentially all the methods on this do lock the sync-object -
something like:

public Foo Bar(...) {
lock(SyncRoot) {
return Items.Bar();
}
}

(if you see what I mean)

Marc
From: NvrBst on
On Feb 22, 11:45 am, Marc Gravell <marc.grav...(a)gmail.com> wrote:
> > Ahh, your right.  When I read "SychronizedCollection<T>" I thought it
> > would autolock at the lower levels to ensure no crashing and the such
>
> It appears to lock for individual operations; but *generally* in my
> experience you need to consider multiple operations as a transaction
> for it to be useful (whether that is the duration of a foreach, or a
> "contains/add" pair, etc).
>
> But essentially all the methods on this do lock the sync-object -
> something like:
>
> public Foo Bar(...) {
>   lock(SyncRoot) {
>     return Items.Bar();
>   }
>
> }
>
> (if you see what I mean)
>
> Marc

Ahh, it has its uses then! :) Thanks for the update, and all the
help ya've given.

NB
 | 
Pages: 1
Prev: load Dll Error
Next: DataGridView footer