![](/img/trans.png)
[英]c# Get Active Window Text (causes vshost32.exe has stopped working)
[英]c# Multithreading Issue / vshost32-clr.exe has stopped working
我对c#和多线程还是陌生的,最近我在编写的工具中遇到了一些障碍。 该工具旨在生成和启动一堆HttpWebRequests。 现在,它可以在单线程上正常工作,但是一旦我开始在3个左右的工作线程中划分任务时,程序崩溃就会给我以下消息。
“ vshost32-clr.exe停止工作”
我想知道是否与制作这些线程的方式有关?
这是我正在使用的C#代码段。 任何建议,以减少这种次充好,将不胜感激。
private void CreateDocuments()
{
int docCount = 0;
ArrayList vsIDs = docRepo.GetVersionIDList();
ArrayList versionList = new ArrayList();
foreach (string vsID in vsIDs)
{
Document[] docs = docRepo.GetVersionSeries(vsID);
versionList.Add(docs);
if (versionList.Count == 3)
{
Console.WriteLine("Launch Thread");
Document[] docs1 = (Document[])versionList[0];
Document[] docs2 = (Document[])versionList[1];
Document[] docs3 = (Document[])versionList[2];
Worker w1 = new Worker(docs1);
Worker w2 = new Worker(docs2);
Worker w3 = new Worker(docs3);
Thread t1 = new Thread(new ThreadStart(w1.Start));
Thread t2 = new Thread(new ThreadStart(w2.Start));
Thread t3 = new Thread(new ThreadStart(w3.Start));
Console.WriteLine("Threads Started");
t1.Start();
t2.Start();
t3.Start();
//Wait until all threads have started
while (!t1.IsAlive || !t2.IsAlive || !t3.IsAlive) { Console.WriteLine("Waiting for Threads to Start"); }
Console.WriteLine("Wait on Threads");
t1.Join();
docCount += docs1.Length;
t2.Join();
docCount += docs2.Length;
t3.Join();
docCount += docs3.Length;
log.Info(docCount + " Documents Imported");
versionList.RemoveRange(0, 3);
}
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
public class Worker
{
ImportToolWebDAV itwd = new ImportToolWebDAV();
Document[] docs;
public Worker(Document[] _docs)
{
docs = _docs;
}
public void Start()
{
HttpStatusCode status = HttpStatusCode.OK;
foreach (Document doc in docs)
{
status = itwd.createDocument(doc);
}
Console.WriteLine("Thread finished");
}
}
这样做(或至少应该做什么)是获取“文档”对象的数组,并为3个数组的每组启动3个线程,然后等待它们完成生成那些WebDAV PUT请求。 这确实是为了测试线程输出而编写的粗糙代码,但是我认为在这种状态下还可以。
如果您有台Dell机器,则可能要检查此链接,因为“ vshost32-clr.exe已停止工作”
http://social.msdn.microsoft.com/Forums/zh-CN/vbide/thread/308a2e5b-f486-4eb6-9276-5cc816665b86
我希望这有帮助...
〜 布彭德拉
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.