Hi All,
The future I want use ListBox. Then Fill the ListBox with a lot of Items.We find the error as bellow;
Managed Debugging Assistant 'ContextSwitchDeadlock'
Message=Managed Debugging Assistant 'ContextSwitchDeadlock' : 'The CLR has been unable to transition from COM context 0xed8788 to COM context 0xed86d0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.'
This is code;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Learning_10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 5000000; i++)
{
listBox1.Items.Add(i);
}
vScrollBar1.Maximum = listBox1.Items.Count;
}
private void Form1_Load(object sender, EventArgs e)
{
vScrollBar1.Height = listBox1.Height;
vScrollBar1.Left = listBox1.Left + listBox1.Width;
vScrollBar1.Top = listBox1.Top;
}
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
listBox1.TopIndex = e.NewValue;
}
}
}