Error in scheduled job

Vote:
 

Hi,

I have a scheduled job that processes XML, adds data and logs each add using Elmah. Our client is testing the with roughly 3500 records in the XML and has found that on one occasion (so far) that two of the records did not process (I'm assuming the last two). The error presented suggests the TCP session ending and the new session token not matching - I presume due to the time taken for processing.

Error: System.ArgumentException: Invalid token for impersonation - it cannot be duplicated

Stack trace points to the line of code in bold:

//log outside of http context
//windows identity can be disposed so recreated it
//(e.g. this was necessart for episerver scheduled task which runs under web app outside of http context)
var token = WindowsIdentity.GetCurrent().Token;
var identity = new WindowsIdentity(token);
var principal = new WindowsPrincipal(identity);
Thread.CurrentPrincipal = principal;

I've not seen this before even with jobs that take some time to process. Anyone have any ideas on how to prevent this error?

Thanks,

Mark

#142074
Nov 30, 2015 13:07
Vote:
 

Any thoughts?

#142172
Dec 03, 2015 11:32
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.