#region Copyright(c) Travis Robinson
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using libusbK;
namespace Handle.Test
{
public partial class fHandleTest : Form
{
private LstK LstKField;
private List<LstK> LstKList = new List<LstK>();
private TextBoxTraceListener mListener;
public fHandleTest()
{
InitializeComponent();
}
~fHandleTest()
{
}
private void createAndExplictlyDestroyToolStripMenuItem_Click(object sender, EventArgs e)
{
LstK lstTemp = new LstK(KLST_FLAG.NONE);
lstTemp.Dispose();
}
private void runGarbageCollectorToolStripMenuItem_Click(object sender, EventArgs e)
{
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
}
private void referenceToolStripMenuItem_Click(object sender, EventArgs e)
{
LstK lstTemp = new LstK(KLST_FLAG.NONE);
LstKList.Add(lstTemp);
LstKField = lstTemp;
}
private void derefrenceToolStripMenuItem_Click(object sender, EventArgs e)
{
if (LstKList.Count > 0)
{
LstKList.Clear();
}
else
{
LstKField = null;
}
}
private void createWithoutExplictDestroyToolStripMenuItem_Click(object sender, EventArgs e)
{
LstK lstTemp = new LstK(KLST_FLAG.NONE);
int count = 0;
lstTemp.Count(ref count);
}
private void fHandleTest_Load(object sender, EventArgs e)
{
mListener = new TextBoxTraceListener(txtOutput, ThreadPriority.Lowest);
Debug.Listeners.Add(mListener);
}
private void fHandleTest_FormClosed(object sender, FormClosedEventArgs e)
{
Debug.Listeners.Remove(mListener);
mListener.Free();
}
private void exhaustAllHandlesToolStripMenuItem_Click(object sender, EventArgs e)
{
LstKList.Clear();
LstKField = null;
int count = 0;
try
{
while (true)
{
new LstK(KLST_FLAG.NONE);
count++;
}
}
catch
{
}
Debug.Print("All handles exhausted. Count:{0}", count);
}
private void testListenerToolStripMenuItem_Click(object sender, EventArgs e)
{
new TestListener(64);
}
}
}