论坛里面装不了,代码在这里:
http://blog.csdn.net/labilaoxin/article/details/7004524现在2个问题:
1、内存占用过高。启动后15M左右,然后慢慢增加到70M左右,好像是系统的自动资源回收,才又回到15M,如此往返。2、开机启动老是不成功,不知道是不是要依存与其他服务?想请高手帮忙优化优化,万分感谢!
有好的意见均给分。一贴不够再发2贴!
http://blog.csdn.net/labilaoxin/article/details/7004524现在2个问题:
1、内存占用过高。启动后15M左右,然后慢慢增加到70M左右,好像是系统的自动资源回收,才又回到15M,如此往返。2、开机启动老是不成功,不知道是不是要依存与其他服务?想请高手帮忙优化优化,万分感谢!
有好的意见均给分。一贴不够再发2贴!
.net很好会出现内存泄露,但是要注意些非托管资源要及时释放,基本上所有实现IDisposable的就要dispose即可。
class BoHao
{
private static Mutex mutex = new Mutex();
private Process dailer = new Process();
public int Desc;
string EntryName = "宽带连接";
string user = "lanxxxxxxxxxx";
string pwd = "********";
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
// 返回18失败,返回81成功
public int IsConnectedToInternet()
{
InternetGetConnectedState(out Desc, 0);
return Desc;
}
public void StartDailer()
{
try
{
if (!IsAlive("rasdial"))
{
mutex.WaitOne();
dailer.StartInfo.FileName = "rasdial.exe";
dailer.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
dailer.StartInfo.Arguments = EntryName + " " + user + " " + pwd;
dailer.Start();
mutex.ReleaseMutex();
}
}
catch (Exception ee)
{
ee.ToString();
}
finally
{
}
dailer.Close();
}
private bool IsAlive(string name)
{
Process[] ps = Process.GetProcessesByName(name);
if (ps.Length > 0)
{
return true;
}
else
{
return false;
}
}
}