A New Internet Library: Add Your Website/Blog or Suggest A Website/Blog to our Free Web Directory http://anil.myfunda.net.

Its very simple, free and SEO Friendly.
Submit Now....

Thursday, July 24, 2008

Multithreading deadlock questions

 I don't know which section to post my problem but this seems relevant.

 

Currently I'm working on a product that requires multithreading in C#. I'm using VS.net 2005.

The requirement is to connect to a third party web service multiple times from my own webservice. Each request to this 3rd party webservice might take some minutes.
So really can't rely on sending these multiple requests sequentially. I thought I'll use .net thread pool and send requests parallely opening concurrent threads.
I have pasted sample code at the end of this email.

Before I tell you what I am doing in my code, my requirement is that each response from the third party service .i.e result from every concurrent thread should be stored in a common data structure (I used a global array list in this case) and then different values stored in that data structure can be played around with . Values retrieved from different webservice calls don't have to be in sync. I just store the return result of this third party webservice in a global array list.

Now the problem is: I AM FACING SOME STUPID DEAD LOCK. Don't know why
Do you think I am missing something vital here.
Your help would be much appreciated.

Thanks,
Jas


/////////////////////////////////////////////////////////////////////

static object workerLocker = new object();

static int runningWorkerThreads = 10;

public in getData()
{
     for (int i = 0; i < runningWorkerThreads; i++)
     {
          ///do something

          ThreadPool.QueueUserWorkItem(Call_DataService, arrDTRow); //where arrDTRow is an arraylist
     }

     lock (workerLocker)
     {
         while (runningWorkerThreads > 0)
                Monitor.Wait(workerLocker);
     }

}

private void Call_DataService(object instance)
{
      // do something
     lock (workerLocker)
     {
          runningWorkerThreads--;
          Monitor.Pulse(workerLocker);
      }

}

//////////////////////////////////////////////
////////////////////////////////////////////



Source Click Here.

No comments:

Post a Comment

Post your comments here:

Originals Enjoy