开发者

c# Multithreading Issue / vshost32-clr.exe has stopped working

I'm new to both c# and multi-threading and I've recently hit a bit of a roadblock in the tool I'm writing. The tool is designed to generate and launch a bunch of HttpWebRequests. Right now it's working fine single threaded, but as soon as I started to divy out the task amongst 3 or so worker threads, the program crashes giving me the following message.

"vshost32-clr.exe has stopped working"

I'm wondering if it has to do with how I'm going about making these threads?

Here is the c# code snippet I'm using. Any recommendations for making this a bit less shoddy would be greatly appreciated.

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();
  开发者_C百科          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");
    }
}

What this is doing (or at least what it should be doing) is fetching arrays of "Document" objects, and launching 3 threads for every set of 3 arrays, then waiting for them to finish generating those WebDAV PUT Requests. This is really rough code written just for the purpose of testing threading out, but I assumed that in this state it was still fine.


You may want to check this link if you have a dell machine, for "vshost32-clr.exe has stopped working"

http://social.msdn.microsoft.com/Forums/en-NZ/vbide/thread/308a2e5b-f486-4eb6-9276-5cc816665b86

Further on AppInit_dlls

I hope this helps...

~bhupendra

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜