//统计源文件行数
string path = currentPath + sourceIPstring;
if (!File.Exists(path))
{
MessageBox.Show("未找到对应的域名源文件,程序即将关闭,请确认源文件存在的情况下,打开本软件!");
this.Close();
}
int count = 0;
StreamReader countstream = new StreamReader(path);
while (countstream.ReadLine() != null)
{
count++;
}
countstream.Close(); //初始化线程数据
Thread[] mythread = new Thread[301]; //初始化进度条
progressBar1.Minimum = 1;
progressBar1.Maximum = count;
progressBar1.Value = 1; //读取域名
int i = 0;
StreamReader readstream = new StreamReader(path);
string linestring = readstream.ReadLine();
string domainName = "";
string domainAddress = "";
while (linestring != null)
{
try
{
i++;
if (linestring.Length != 0)
{
int indexof = linestring.IndexOf(" ");
if (indexof <= 0)
indexof = linestring.Length;
domainName = linestring.Substring(0, indexof);
domainAddress = linestring.Substring(indexof, linestring.Length - indexof); int k = 300 - i;
if (k == 1)
i = 0; ping HostPing = new ping(); //创建一个ping实例 HostPing.fileString = currentPath + companyIPString; HostPing.domainName = domainName; HostPing.domainIPString = domainAddress; HostPing.ul = new UpdateList(UpdateMyList); t1 = mythread[k] = new Thread(new ThreadStart(HostPing.scan)); //初始化一个线程实例 mythread[k].Start();
}
linestring = readstream.ReadLine();
}
catch(Exception ex)
{
// MessageBox.Show(ex.Message);
}
}
readstream.Close();上面一段程序中,在读取文件达到 50K以上,就会出现内存溢出错误,小于50K时则一切正常,请高手 指点一下是否程序中某个地方没有释放内存造成,如果 是,请指点一二,谢谢大大们
string path = currentPath + sourceIPstring;
if (!File.Exists(path))
{
MessageBox.Show("未找到对应的域名源文件,程序即将关闭,请确认源文件存在的情况下,打开本软件!");
this.Close();
}
int count = 0;
StreamReader countstream = new StreamReader(path);
while (countstream.ReadLine() != null)
{
count++;
}
countstream.Close(); //初始化线程数据
Thread[] mythread = new Thread[301]; //初始化进度条
progressBar1.Minimum = 1;
progressBar1.Maximum = count;
progressBar1.Value = 1; //读取域名
int i = 0;
StreamReader readstream = new StreamReader(path);
string linestring = readstream.ReadLine();
string domainName = "";
string domainAddress = "";
while (linestring != null)
{
try
{
i++;
if (linestring.Length != 0)
{
int indexof = linestring.IndexOf(" ");
if (indexof <= 0)
indexof = linestring.Length;
domainName = linestring.Substring(0, indexof);
domainAddress = linestring.Substring(indexof, linestring.Length - indexof); int k = 300 - i;
if (k == 1)
i = 0; ping HostPing = new ping(); //创建一个ping实例 HostPing.fileString = currentPath + companyIPString; HostPing.domainName = domainName; HostPing.domainIPString = domainAddress; HostPing.ul = new UpdateList(UpdateMyList); t1 = mythread[k] = new Thread(new ThreadStart(HostPing.scan)); //初始化一个线程实例 mythread[k].Start();
}
linestring = readstream.ReadLine();
}
catch(Exception ex)
{
// MessageBox.Show(ex.Message);
}
}
readstream.Close();上面一段程序中,在读取文件达到 50K以上,就会出现内存溢出错误,小于50K时则一切正常,请高手 指点一下是否程序中某个地方没有释放内存造成,如果 是,请指点一二,谢谢大大们
{
k = i++ % 301;
t1 = mythread[k] = new Thread(new ThreadStart(HostPing.scan)); //<--?!
mythread[k].Start();
}
这个方法一直循环的?
囧你类名用小写,对象用大写的,这习惯
int k = 300 - i;
if (k == 1)
i = 0;
我这个上面有控制线程数量呀!
是吗?你要是写成if(k==1) break;倒是可行。
你也知道while循环没有停。
那你不知道循环内的t1 = mythread[k] = new Thread(new ThreadStart(HostPing.scan));还在继续创建线程?
double curValule = 0;//增加值的时候
curValue += valuePlusPerTime;
progress1.Value = (int)curValue;
if (k == 1)
{
i = 0;
if(myThread[i] != null)
myThread[i].Abort();
}