ListView 성능 개선
This commit is contained in:
91
NewsForm.cs
91
NewsForm.cs
@@ -79,24 +79,17 @@ namespace NewsCrawler
|
|||||||
int m_iCrawlInterval = 500;
|
int m_iCrawlInterval = 500;
|
||||||
bool m_bBuy = false;
|
bool m_bBuy = false;
|
||||||
|
|
||||||
List<string> m_URLs = new List<string>();
|
ConcurrentQueue<ListViewItem> m_NewItems = new ConcurrentQueue<ListViewItem>();
|
||||||
|
ConcurrentBag<string> m_URLs = new ConcurrentBag<string>();
|
||||||
|
|
||||||
System.Timers.Timer m_SystemTimer = new System.Timers.Timer();
|
System.Timers.Timer m_SystemTimer = new System.Timers.Timer();
|
||||||
|
|
||||||
ConcurrentQueue<PRICE_CHECK_DATA> m_PriceCheckList = new ConcurrentQueue<PRICE_CHECK_DATA>();
|
ConcurrentQueue<PRICE_CHECK_DATA> m_PriceCheckList = new ConcurrentQueue<PRICE_CHECK_DATA>();
|
||||||
System.Timers.Timer m_PriceCheckTimer = new System.Timers.Timer();
|
System.Timers.Timer m_PriceCheckTimer = new System.Timers.Timer();
|
||||||
|
|
||||||
delegate void InsertListView(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double responseT, bool bInitial);
|
|
||||||
InsertListView m_InsertListViewDelegate = null;
|
|
||||||
|
|
||||||
Crawler m_Crawler = null;
|
Crawler m_Crawler = null;
|
||||||
|
|
||||||
ExcelHandler m_Excel = null;
|
ExcelHandler m_Excel = null;
|
||||||
|
|
||||||
object m_lvListLock = new object();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public NewsForm()
|
public NewsForm()
|
||||||
{
|
{
|
||||||
@@ -116,8 +109,6 @@ namespace NewsCrawler
|
|||||||
|
|
||||||
//MessageBox.Show("Keywords : \n\n" + m_Condition.GetKeywordsCnt());
|
//MessageBox.Show("Keywords : \n\n" + m_Condition.GetKeywordsCnt());
|
||||||
|
|
||||||
m_InsertListViewDelegate = new InsertListView(this.InsertItem);
|
|
||||||
|
|
||||||
m_Crawler.ReadKIND(true);
|
m_Crawler.ReadKIND(true);
|
||||||
m_Crawler.ReadDart(true);
|
m_Crawler.ReadDart(true);
|
||||||
m_Crawler.ReadEtoday(true);
|
m_Crawler.ReadEtoday(true);
|
||||||
@@ -532,30 +523,21 @@ namespace NewsCrawler
|
|||||||
if(strURL == "")
|
if(strURL == "")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
lock(m_URLs)
|
return m_URLs.Any(s => s == strURL);
|
||||||
return m_URLs.Any(s => s == strURL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertItem(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double dElapseT, bool bInitial)
|
public void InsertItem(string strTitle, string strName, string strCode, DateTime time, DateTime ResTime, string strURL, string strRef, double dElapseT, bool bInitial)
|
||||||
{
|
{
|
||||||
try
|
if (IsDuplicatedURL(strURL) == true)
|
||||||
{
|
return;
|
||||||
if(this.InvokeRequired)
|
|
||||||
{
|
|
||||||
this.Invoke(m_InsertListViewDelegate, strTitle, strName, strCode, time, ResTime, strURL, strRef, dElapseT, bInitial);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(IsDuplicatedURL(strURL) == true)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int iID = lvList.Items.Count+1;
|
int iID = lvList.Items.Count + 1;
|
||||||
|
|
||||||
CodeList.CODE_VALUE Code = m_CodeList.SearchCode(strTitle);
|
CodeList.CODE_VALUE Code = m_CodeList.SearchCode(strTitle);
|
||||||
if(bInitial == false && Code != null)
|
if (bInitial == false && Code != null)
|
||||||
ProcessSearchAndBuy(new NEWS_ITEM(iID, strTitle, strCode, Code, time, ResTime, strRef, strURL, (float)dElapseT));
|
ProcessSearchAndBuy(new NEWS_ITEM(iID, strTitle, strCode, Code, time, ResTime, strRef, strURL, (float)dElapseT));
|
||||||
|
|
||||||
var AddedItem = lvList.Items.Add(new ListViewItem(new string[] {
|
var newItem = new ListViewItem(new string[] {
|
||||||
iID.ToString(),
|
iID.ToString(),
|
||||||
time.ToString("HH:mm:ss"),
|
time.ToString("HH:mm:ss"),
|
||||||
ResTime.ToString("HH:mm:ss:fff"),
|
ResTime.ToString("HH:mm:ss:fff"),
|
||||||
@@ -568,31 +550,42 @@ namespace NewsCrawler
|
|||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
strURL }));
|
strURL });
|
||||||
|
newItem.UseItemStyleForSubItems = false;
|
||||||
|
if (Code == null && strCode != "")
|
||||||
|
newItem.SubItems[chCodeName.Index].BackColor = Color.Gray;
|
||||||
|
|
||||||
AddedItem.UseItemStyleForSubItems = false;
|
m_NewItems.Enqueue(newItem);
|
||||||
if(Code == null && strCode != "")
|
m_URLs.Add(strURL);
|
||||||
AddedItem.SubItems[chCodeName.Index].BackColor = Color.Gray;
|
|
||||||
|
|
||||||
if(lvList.Items.Count < 2)
|
Action insert = delegate
|
||||||
|
{
|
||||||
|
if (m_NewItems.IsEmpty == false)
|
||||||
|
{
|
||||||
|
List<ListViewItem> itemList = new List<ListViewItem>();
|
||||||
|
ListViewItem item;
|
||||||
|
while (m_NewItems.TryDequeue(out item))
|
||||||
|
itemList.Add(item);
|
||||||
|
|
||||||
|
lvList.BeginUpdate();
|
||||||
|
lvList.Items.AddRange(itemList.ToArray());
|
||||||
|
if (lvList.Items.Count < 2)
|
||||||
{
|
{
|
||||||
foreach(ColumnHeader col in lvList.Columns)
|
foreach (ColumnHeader col in lvList.Columns)
|
||||||
col.Width = -2;
|
col.Width = -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
lock(m_URLs)
|
if (bInitial == false)
|
||||||
m_URLs.Add(strURL);
|
|
||||||
|
|
||||||
if(bInitial == false)
|
|
||||||
lvList.Sort();
|
lvList.Sort();
|
||||||
|
lvList.EndUpdate();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
Util.Log(Util.LOG_TYPE.ERROR, ex.Message + Environment.NewLine + ex.StackTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (lvList.InvokeRequired)
|
||||||
|
lvList.Invoke(insert);
|
||||||
|
else
|
||||||
|
insert();
|
||||||
|
}
|
||||||
|
|
||||||
private void SystemTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
private void SystemTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -639,6 +632,9 @@ namespace NewsCrawler
|
|||||||
|
|
||||||
private void UpdateStartPrice(int iID, int iPrice)
|
private void UpdateStartPrice(int iID, int iPrice)
|
||||||
{
|
{
|
||||||
|
if (iID < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if(lvList.InvokeRequired)
|
if(lvList.InvokeRequired)
|
||||||
{
|
{
|
||||||
lvList.BeginInvoke((MethodInvoker)delegate ()
|
lvList.BeginInvoke((MethodInvoker)delegate ()
|
||||||
@@ -774,9 +770,11 @@ namespace NewsCrawler
|
|||||||
{
|
{
|
||||||
SortOrder Order = (lvList.Sorting == SortOrder.Descending || lvList.Sorting == SortOrder.None) ? SortOrder.Ascending : SortOrder.Descending;
|
SortOrder Order = (lvList.Sorting == SortOrder.Descending || lvList.Sorting == SortOrder.None) ? SortOrder.Ascending : SortOrder.Descending;
|
||||||
|
|
||||||
|
lvList.BeginUpdate();
|
||||||
lvList.ListViewItemSorter = new ListViewItemComparer(e.Column, Order);
|
lvList.ListViewItemSorter = new ListViewItemComparer(e.Column, Order);
|
||||||
lvList.Sorting = Order;
|
lvList.Sorting = Order;
|
||||||
lvList.Sort();
|
lvList.Sort();
|
||||||
|
lvList.EndUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void lvList_DoubleClick(object sender, EventArgs e)
|
private void lvList_DoubleClick(object sender, EventArgs e)
|
||||||
@@ -1033,7 +1031,10 @@ namespace NewsCrawler
|
|||||||
if(double.TryParse(item1.SubItems[m_iColumn].Text, out num1) &&
|
if(double.TryParse(item1.SubItems[m_iColumn].Text, out num1) &&
|
||||||
double.TryParse(item2.SubItems[m_iColumn].Text, out num2))
|
double.TryParse(item2.SubItems[m_iColumn].Text, out num2))
|
||||||
{
|
{
|
||||||
return (num1>num2)?1:-1;
|
if (m_Order == SortOrder.Ascending)
|
||||||
|
return (num1 > num2) ? 1 : -1;
|
||||||
|
else
|
||||||
|
return (num1 > num2) ? -1 : 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
14
Program.cs
14
Program.cs
@@ -14,16 +14,16 @@ namespace NewsCrawler
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
//try
|
try
|
||||||
//{
|
{
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new NewsForm());
|
Application.Run(new NewsForm());
|
||||||
//}
|
}
|
||||||
//catch(Exception ex)
|
catch (Exception ex)
|
||||||
//{
|
{
|
||||||
// Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
|
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user