111,072
社区成员




static void OpenConnection(SqlConnection conn)
{
if (conn.State != ConnectionState.Open)
conn.Open();
}
static void TestUnManager()
{
try
{
for (int i = 0; i < 10; i++)
{
SqlConnection conn = new SqlConnection("server=20080827-1517; User ID=sa;Password=cherry; database=InforSys; min pool size=2; max pool size=3");
TimeSpan bts = DateTime.Now.TimeOfDay;
OpenConnection(conn);
TimeSpan ets = DateTime.Now.TimeOfDay;
TimeSpan ts = bts - ets;
Console.WriteLine(ts);
//conn.Close();
conn = null;
Thread.Sleep(1000);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
static void TestManager()
{
for (int i = 0; i < 10; i++)
{
GetTable();
}
}
static void GetTable()
{
using (SqlConnection conn = new SqlConnection("server=20080827-1517; User ID=sa;Password=cherry; database=InfoSys; min pool size=20; max pool size=100"))
{
SqlCommand cmd = new SqlCommand("select * from gtl_comp", conn);
using (SqlDataAdapter da = new SqlDataAdapter())
{
DataTable dt = new DataTable();
da.SelectCommand = cmd;
da.Fill(dt);
dt = null;//这分两个,一个有,一个没有
}
}
}
public class Test
{
private string name;
public Test(string name)
{
this.name = name;
StringBuilder sb = new StringBuilder(10240000);
for (int i = 0; i < 102400; i++)
sb.Append(name+i);
}
~Test()
{
Console.WriteLine(name+"执行到析构");
}
static void Main(string[] args)
{
//TestUnManager();
//TestManager();
NotSetNull();
SetNull();
}
static void NotSetNull()
{
for (int i = 0; i < 100; i++)
{
Test t = new Test("ojek"+i);
}
}
static void SetNull()
{
for (int i = 100; i < 200; i++)
{
Test t = new Test("ojek" + i);
t = null;
}
}
}