Mar 31, 2009 at 12:55 PM

 I would like to know why WorkItemsGroup is registered in STP only when there ares itens queued on it. There is a big performance impact in the operation of registering and unregistering it on the internal Hashtable of STP.

Mar 31, 2009 at 7:01 PM

First, thank you for the question, it made me to think.

The STP has to manage the collection of WorkItemsGroup that it created for several reasons:
1. When a WorkItemsGroup is started suspended, the STP has to wake it up.
2. When the STP is cancelled, the WorkItemsGroups are cancelled also.
3. When the user fires and forgets work items into a WorkItemsGroup, the STP must keep a reference to the wig, otherwise it will be collected by the GC.
public void myfunc()
IWorkItemsGroup wig = stp.CreateWorkItemsGroup(10);
Notice that wig is a local variable, and it will be collected, unless the STP keeps a reference to it.

To come to the point when a WorkItemsGroup contains work items, the STP keeps a reference to it because of the above reasons. When the WorkItemsGroup is empty, the STP discards the reference so the GC may collect it.

As for the solution as a synchronized Hashtable, maybe it is not the best solution and can be optimized. If you have any suggestions then be my guest. I am always happy for improvements.


Jan 28, 2010 at 2:43 PM

Hi Ami,


I know there is a long time, But I got some time to work on this again.

I've been thiking in a alternative implementation to the WorkItemsGroup registration and I like to hear what you think about the below alternative.


1) I would like to register WorkItemsGroup on CreateWorkItemsGroup so we can match the 3 requirements

2) When EnqueueToSTPNextWorkItem discover there is no itens in the group, its schedule itself for Unregister after a timeout, so there is no memory leak and will reduce the number of Register/Unregister to STP.



Jorge Rocha Gualtieri