|
มาดูโค้ดกันเถอะ ...
- Public Class frmFastAddItem
- '/ Start-Stop Timer
- Private mTimeDouble As Double
- Private sWatch As New Stopwatch()
- '/ Technique
- Private Sub FastAddItem(ByVal MaxItem As Integer)
- Dim lst As List(Of Object) = New List(Of Object)(MaxItem)
- For i As Integer = 1 To MaxItem
- lst.Add(i)
- Next
- cmbTest.Items.AddRange(lst.ToArray())
- '//
- cmbTest.SelectedIndex = cmbTest.Items.Count - 1
- End Sub
- '/ Normal.
- Private Sub AddItemVB(ByVal MaxItem As Integer)
- For i = 1 To MaxItem
- cmbTest.Items.Add(i)
- Next
- cmbTest.SelectedIndex = cmbTest.Items.Count - 1
- End Sub
- Private Sub btnAddItemFast_Click(sender As System.Object, e As System.EventArgs) Handles btnAddItemFast.Click
- cmbTest.Items.Clear()
- lblTimer.Text = "Timer List: "
- GroupBox1.Text = " Test with List "
- sWatch.Reset()
- sWatch.Start()
- Cursor = Cursors.WaitCursor
- '//
- Call FastAddItem(20000)
- '//
- Cursor = Cursors.Default
- sWatch.Stop()
- mTimeDouble = sWatch.ElapsedMilliseconds * 0.001
- lblTimer.Text = lblTimer.Text & mTimeDouble.ToString & " sec."
- End Sub
- Private Sub btnAddItem_Click(sender As System.Object, e As System.EventArgs) Handles btnAddItem.Click
- cmbTest.Items.Clear()
- lblTimer.Text = "Timer normal code: "
- GroupBox1.Text = " Test with normal code "
- sWatch.Reset()
- sWatch.Start()
- Cursor = Cursors.WaitCursor
- '//
- Call AddItemVB(20000)
- '//
- Cursor = Cursors.Default
- sWatch.Stop()
- mTimeDouble = sWatch.ElapsedMilliseconds * 0.001
- lblTimer.Text = lblTimer.Text & mTimeDouble.ToString & " sec."
- End Sub
- Private Sub frmFastAddItem_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
- lblTimer.Text = ""
- End Sub
- End Class
คัดลอกไปที่คลิปบอร์ด
ดาวน์โหลดโค้ดฉบับเต็ม VB.NET (2010) ได้ที่นี่ ...
|
|