내 프로젝트는 BackgroundThread를 사용하여 휴즈 목록을 목록보기에로드합니다. 매우 빠른 성능을 보였지만 거의 100 %의 CPU를 사용합니다. CPU 사용량을 줄이지 않고도 높은 CPU 사용량을 피할 수있는 해결 방법이 있습니까? 공연? 사전에대용량 파일을 읽을 때 높은 CPU 사용을 피하는 방법
void readfile() {
deg_readfile read = new deg_readfile(readfileasync);
read.BeginInvoke(new AsyncCallback(callback),null);
}
void readfileasync(){
string[] strs = File.ReadAllLines("hughlist.txt");
List<ListViewItem> _itemlst = new List<ListViewItem>();
ListViewItem _item;
int x = 0;
//problem start here
foreach (string str in strs) {
_item = new ListViewItem(str);
for (int i = 0; i < 6; i++) {
_item.SubItems.Add("");
}
_itemlst.Add(_item);
x++;
_item = null;
}
}
void callback(IAsyncResult ae) {
Console.WriteLine("finished");
}
delegate void deg_readfile();
static void Main(string[] args)
{
Program prog = new Program();
Thread t=new Thread(new ThreadStart(prog.readfile))
{
IsBackground = true,
Priority = ThreadPriority.Lowest
};
t.SetApartmentState(ApartmentState.MTA);
t.Start();
Console.Read();
}
감사 : 나는 netframework 3.5
코드를 사용합니다.
업데이트 :
시스템 구성 :
프로세서 인텔 (R) 코어 (TM) i3-2328M CPU에서 @의 2.20GHZ 2.11 GHZ 설치된 메모리 1.00 GB 시스템 유형 : 32 비트 운영 시스템
파일이 있습니다 비동기 아니라 1 개 백만 라인
시스템 구성, 보유한 논리 프로세서의 수는 얼마입니까? CPU가 얼마나 오래 100 %를 유지합니까? 파일의 크기는 얼마나됩니까? –
@SriramSakthivel 파일의 크기가 중요하다고 생각하지 않습니다. 중요한 것은 큰 문제입니다. :) 그러나 mysticgirltk는 OS 구성, OS 및 CPU 구조, 메모리 크기 및 CPU 클럭을 입력하십시오. 시간 – niceman
@niceman 거대한 용어입니다. 얼마나 거대한 거죠? 이 질문에 대답 할 수 있습니까? 아마도 그렇지 않습니다. 그래서 혼란을 피하기 위해 나는 파일 크기를 물었다. –