views:

330

answers:

2

Hi all,

I have been coding for some days on a webpart now. The point of this webpart is to clean up a given document library. I have 16 000+ msg files in there and I have to validate the To and From headers of each msg file against some given rules.

All is well, except for the fact that this process takes forever. All possible values that are allowed in To or From are stored in SPLists in SharePoint itself.

I was able to split the process of validating against the business rules and the webpart itself by calling that specific mail validate method asynchronously.

Now, the technical part where I am a bit lost:

The method returns a Dictionary which I want to bind to a CheckBoxList. So how can I do this? Because I have to wait until my asynchronous mail validate method is done until I can bind the datasource of the CheckBoxList?

My webpart consists actually out of a usercontrol which I load in the webpart.

A: 

Have you considered using jQuery/Ajax instead of usercontrols and direct code behind? Thats how I handle asynchronous loading on my webparts, bearing in mind that 99% of our development uses xml/xslt for html generation.

Aquinas
I do not quite understand your answer. I use a user control because this seems a more clean approach to me then directly coding in the web part itself. I have just one method that I need to run asynchronously. A C# method. I don't think that jQuery/AJAX can help with this or am I wrong?
Maarten Louage
A: 

Your async method should call a callback function which continues processing. This callback should do the binding; it only occurs when the async process is done..

Alternatively, with that many items you might still run into problems. Why not create a fully asynchronous process? Your webpart could schedule a run-once timer job in SharePoint which executes your cleanup completely asynchronously. Or record the details of your job in a list which can be picked up by a scheduled executeable or stsadm command extention. This will work with any number of items in your list.

ArjanP
Thank you. I have run indeed into trouble with that many items. I have applied your solution of storing my items which I need to delete in a list. My webpart is then checking if that list contains items or not and acts upon that. This is not really ideal because I need to reload the page which contains the webpart.
Maarten Louage