public void static Main() { Someclass instance = new Someclass(); instance.SomeInstanceMethod(); SomeStaticMethod(instance); }
public void TestCts() { using (var cts = new CancellationTokenSource()) { //var newctsDoesNotLeak = new CancellationTokenSource(); // by itself (not from linked).. doesn't leak mem or handles //var myevent = CreateEvent(IntPtr.Zero, false, false, $"aa{i}"); // leaks kernel handles, this is used internally in CTS //CloseHandle(myevent); // must close else leaks kernel handles //var timer = new Timer((st) => //{ //}, state: 0, dueTime: 0, period: 1000); //this leaks mem. //timer.Dispose(); // must dispose else leaks. Not a CTS leak, but used internally //var mre = new ManualResetEvent(initialState: false);// leaks mem and handles. Not a CTS leak (used internally by CTS) //var cts1 = CancellationTokenSource.CreateLinkedTokenSource(new CancellationToken[] { cts.Token }); //cts1.Dispose(); // must dispose else leaks CTS Leak Type No. 1. Calling Cancel has no effect on the leak: still must call dispose var tk = cts.Token; var cancellationTokenRegistration = tk.Register(() => { }); var x = new Someclass(tk); var x2 = new Someclass(tk); var x3 = new Someclass(tk); ProcessCancellationToken(tk, logger: (str) => { LogMessage(str); }); } //cancellationTokenRegistration.Dispose(); // must dispose else leaks. CTS Leak Type No. 2 //var newcts = new CancellationTokenSource(); //newcts.CancelAfter(TimeSpan.FromMinutes(10)); // this leaks mem. //newcts.Dispose(); // must dispost else leaks CTS Leak Type No. 3 //var newcts = new CancellationTokenSource(); //var handle = newcts.Token.WaitHandle; // this internally lazily instantiates a ManualResetEvent //newcts.Dispose(); // must dispose, else leaks mem and handles. CTS Leak Type No. 4 //var newcts = new CancellationTokenSource(); //var linked = CancellationTokenSource.CreateLinkedTokenSource(newcts.Token); //newcts.Dispose(); // this does not leak: disposing the original cts means the linked won't leak. However, not necessarily recommended }
public void Quickcheck() { Prop.ForAll <int>(i => Someclass.add1(i) == i + 1) .QuickCheckThrowOnFailure(); }
static void Main(string[] args) { Console.WriteLine(Someclass.add1(1)); }
void static SomeStaticMethod(Someclass _this) { System.Console.WriteLine(_this.ToString()); }
public static void Data2() { Someclass foo = new Someclass(); Someclass.Data1(); }