Print Page | Close Window

Coroutine methods and UserState

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2272
Printed Date: 04-Feb-2026 at 1:14pm


Topic: Coroutine methods and UserState
Posted By: stephenmcd1
Subject: Coroutine methods and UserState
Date Posted: 27-Oct-2010 at 7:03pm
It appears that none of the methods on the Coroutine class (Start, StartParallel) take a userState parameter even though the resulting CoroutineOperation has a UserState property - and pretty much all other query-related methods in DevForce provide the userState parameter.  Is this just an oversight?  Can a userState parameter be added to the Coroutine methods?

Thanks!



Replies:
Posted By: kimj
Date Posted: 28-Oct-2010 at 11:06am
In some ways UserState is a legacy of our older async API when async operations did not return a xxOperation (EntityQueryOperation, EntitySaveOperation, etc).  The UserState is used internally to track every async operation uniquely, and can also be used to cancel an async operation.  I guess we tend to forget the fact that it can be used to pass user-defined information between the calling method and the callback.
 
In the case of the Coroutine Start methods, because the Coroutine is not itself asynchronous DevForce does not need a UserState.  A UserState is assigned to the CoroutineOperation, but only because that class is a sub-type of the BaseOperation and a UserState is automatically assigned.   Because the UserState isn't used by DevForce in the Coroutine, we didn't provide a means of providing it.  You can pass parameters into the iterator block via the Start methods, however, and this does in some way give you the same functionality as a user-defined UserState.
 
We can certainly look at adding a UserState parameter to the Start methods and have opened a feature request for this.  Thanks for the feedback.
 
 



Print Page | Close Window