Created
November 27, 2014 10:53
-
-
Save joshrobb/5bcb1f4462424ef53914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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