CLR 无法从 COM 上下文 0x1b0608 转换为 COM 上下文 0x1b0778,这种状态已持续 60 秒。拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的情况下处理一个运行时间非常长的操作。这种情况通常会影响到性能,甚至可能导致应用程序不响应或者使用的内存随时间不断累积。要避免此问题,所有单线程单元(STA)线程都应使用泵式等待基元(如 CoWaitForMultipleHandles),并在运行时间很长的操作过程中定期发送消息。主要代码如下:private void button2_Click(object sender, EventArgs e)
{
filePath = new ArrayList();
getAllFiles(textBox1.Text);
for (int s = 0; s < filePath.Count; s++)
{
foreach (Object obj in filePath)
{
listBox1.Items.Add(obj.ToString());
}
} } public void getAllFiles(string path)
{
if (File.Exists(path))
{
//若为文件,则直接返回
filePath.Add(path);
}
else if (Directory.Exists(path)) //若为 文件夹 则继续。。
{
DirectoryInfo fatherDir = new DirectoryInfo(path); //当前目录
DirectoryInfo[] childDir = fatherDir.GetDirectories(); //当前目录下的文件夹
FileInfo[] fi = fatherDir.GetFiles(); //当前目录下的文件
int counters = fatherDir.GetFiles().Length; //当前目录下的文件个数
for (int i = 0; i < counters; i++)
{
if (fi[i].FullName.IndexOf(".bmp") > 0)
{
filePath.Add(fi[i].FullName); //将当前目录下的文件名保存到ArrayList下
}
}
foreach (DirectoryInfo dir in childDir)
{
Thread.Sleep(10);
getAllFiles(dir.FullName); //递归取得各级目录下的文件及文件夹
}
}
else
{
//非文件 也非文件夹,不处理
filePath.Add(@"Error:路径名【" + path + @"】不正确,请确认!");
}
}
请问这个要怎么解决!
{
filePath = new ArrayList();
getAllFiles(textBox1.Text);
for (int s = 0; s < filePath.Count; s++)
{
foreach (Object obj in filePath)
{
listBox1.Items.Add(obj.ToString());
}
} } public void getAllFiles(string path)
{
if (File.Exists(path))
{
//若为文件,则直接返回
filePath.Add(path);
}
else if (Directory.Exists(path)) //若为 文件夹 则继续。。
{
DirectoryInfo fatherDir = new DirectoryInfo(path); //当前目录
DirectoryInfo[] childDir = fatherDir.GetDirectories(); //当前目录下的文件夹
FileInfo[] fi = fatherDir.GetFiles(); //当前目录下的文件
int counters = fatherDir.GetFiles().Length; //当前目录下的文件个数
for (int i = 0; i < counters; i++)
{
if (fi[i].FullName.IndexOf(".bmp") > 0)
{
filePath.Add(fi[i].FullName); //将当前目录下的文件名保存到ArrayList下
}
}
foreach (DirectoryInfo dir in childDir)
{
Thread.Sleep(10);
getAllFiles(dir.FullName); //递归取得各级目录下的文件及文件夹
}
}
else
{
//非文件 也非文件夹,不处理
filePath.Add(@"Error:路径名【" + path + @"】不正确,请确认!");
}
}
请问这个要怎么解决!
private void button2_Click(object sender, EventArgs e)
{
filePath = new ArrayList();
getAllFiles(textBox1.Text);
for (int s = 0; s < filePath.Count; s++)
{
foreach (Object obj in filePath)
{
listBox1.Items.Add(obj.ToString());
}
}
}改成这样,private void button2_Click(object sender, EventArgs e)
{
Thread th = new Thread(ThreadStart(Doing));
th.Start(); //这样就可以了
}private void Doing()
{
filePath = new ArrayList();
getAllFiles(textBox1.Text);
for (int s = 0; s < filePath.Count; s++)
{
foreach (Object obj in filePath)
{
listBox1.Items.Add(obj.ToString());
}
}
}
{
foreach (Object obj in filePath)
{
listBox1.Items.Add(obj.ToString());
}
}这是什么意思?
你要添加两边?