1
Reply

Sharing a Generic Collection

Ken Linder

Ken Linder

Apr 5 2008 8:05 PM
3.3k
Seems quiet in here, but I will throw this out here anyway.

I have a Windows Forms C# program (using .NET ver 2) that has several heterogeneous threads (BackgroundWorker)  that need to access a common Generic Collection that is a private property in the Form collection.  Example:

BackgroundWorker 1 - Reads POP3 e-mails and places them in the collection.
BackgroundWorker 2 - Scans the collection for work to do.
BackgroundWorker 3 - Scan the collection and report on work done.
BackgroundWorker 4 - Scan the collection and handle trapped exceptions and housekeeping.

Now, when I create each thread, I have this in the BackgroundWorker class...

public MyCollectionClass  MyCollection.

My creating code does...

newBackgroundWorker.MyCollection = GlobalCollection;

Now, I thought that when I did this, I was assigning a reference into the class, not copying the collection.  It seems to be copying the entire collection, not pointing the property in the BackgroundWorker to the global collection.

Thoughts?  How DO I get several threads like this to share a collection?

TIA
-Ken

Upload Source Code  Select only zip and rar file.
Answers (1)