Skip to content

Instantly share code, notes, and snippets.

@joshrobb
Created November 27, 2014 10:53
Show Gist options
  • Save joshrobb/5bcb1f4462424ef53914 to your computer and use it in GitHub Desktop.
Save joshrobb/5bcb1f4462424ef53914 to your computer and use it in GitHub Desktop.
public class LongRunningNHOperation : IDisposable
{
SessionScope session;
int newsessioncount = 250;
Stopwatch stopwatch = Stopwatch.StartNew();
private LongRunningNHOperation() { }
public static LongRunningNHOperation Start(int newsession = 250) {
return new LongRunningNHOperation() {
newsessioncount = newsession,
session = new SessionScope()
};
}
public int OperationCount { get; protected set; }
public void Iterate() {
if (++OperationCount % newsessioncount == 0) {
session.Flush();
session.Dispose();
session = new SessionScope();
}
}
public void Dispose() {
if (session != null) {
session.Flush();
session.Dispose();
}
}
public double OperationsSecond {
get {
return ((double)OperationCount / stopwatch.ElapsedMilliseconds) * 1000;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment