views:

89

answers:

1

I have a workflow, which creates a task and deletes it after the task is edited and its useful information acquired. I created a custom edit form for the task, so I have an SPLongOperation that I can use to stall the page. This is necessary, because if I don't stall the page in some fashion, the person will see the task in the task list for the minute moment before the workflow gets to delete the task, and that is bad. So some code to stall the page until the task is fully deleted is necessary.

I have currently implemented a solution for this, but I am unsatisfied with the approach. It basically is summed up to a while loop that calls SPList.GetItemById until it throws an error. Delibrately attempting to cause an error doesn't sit well with me, but I cannot think of a faster method for checking this. I'm looking for alternatives that would preferably work faster if not as fast, and preferably without relying on catching exceptions. Thank you in advance!

+1  A: 

How about using an SPQuery to lookup the ID and if it doesn't find it then continue. This doesn't throw any exceptions.

Muhimbi
So, initialize a query for the ID outside of the while loop, then run the loop until `SPList.GetItems(q).Count == 0`? Thinking along those lines, I haven't really played with LINQ but would that work any faster?
ccomet
No need to mess around with LINQ, just repeat the query in a loop with a Thread.Sleep(100) and all should be OK. I don't know your exact logic or why this is a problem, but SPQuery is an efficient way to query, even in big lists.
Muhimbi
It isn't a problem... just the purpose of this question is to explore all possibilities. Asking about a similar approach just seemed in-line with that logic.
ccomet