I have a feature receiver with some long running code, hence I use SPLongOperation
and delegate
for better visual appearance. Basically my feature receiver looks like so:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPLongOperation.Begin("Header",
"Caption",
delegate(SPLongOperation longOperation)
{
//custom code here
longOperation.End("http://url", SPRedirectFlags.Static,
HttpContext.Current, null);
});
}
My problem is that when an error occurs within my custom code, the feature still is "activated" - in the features list it still displays as being activated, even though an exception occurred.
How do I throw the exception back to FeatureActivated
or how do I stop the feature from appearing as "activated" even though it ran into an error?
Update:
I know already that the exception thrown inside the delegate
is just not passed to the FeatureActivated
method, hence the feature activated already while the delegate
might still be running.
I could get around using the delegate, but to instantiation a SPLongOperation I need a Page
to pass - how would I get a Page
without having this.Page
inside a feature receiver?
The following should work:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
//Here I need to pass the ManageFeatures.aspx page? Any page? The LongRunningOperation.aspx page?
Page page = new Page();
SPLongOperation operation = new SPLongOperation(page);
operation.Begin();
//custom code here
operation.End("http://url", SPRedirectFlags.Static,HttpContext.Current, null);
});
}
When a feature is thrown within my custom code the exception will be passed to the feature activation and the feature will not be activated - only problem: What page to pass?