Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts, i wanna ask u about thread. i've a problem in threading, i've had webservice that contain 3 method, such as : ReceiveDataStatic, ReceiveDataInvestor, and ReceiveDataValidator.

When the client want to use this service, they can use these methods at the same time. I've confused about the performance of my application,so i've made some thread like this : :~


C#
// This is the web method
[WebMethod]
public void ReceiveDataStatic(object obj)
{
  ClassMessage o = new ClassMessage();
  o.ProcessMessage(obj); // Call ProcessMessage method in other class
}

[WebMethod]
public void ReceiveDataInvestor(object obj)
{
   ClassMessage o = new ClassMessage();
   o.ProcessMessage(obj);
}

[WebMethod]
public void ValidatorDataInvestor(object obj)
{
   ClassMessage o = new ClassMessage();
   o.ProcessMessage(obj);
}




C#
//Class ClassMessage.cs
public void ProcessMessage(object obj)
{
  switch (type)
  {
    case "Data Static":
      oThread1 = new Thread(ParseDataStatic);
      oThread1.Start(obj);
      break;
    case "Data Investor":
      oThread2 = new Thread(ParseDataInvestor);
      oThread2.Start(obj);
      break;
    case "Inventory Validation":
      oThread3 = new Thread(ParseDataInvValidation);
      oThread3.Start(obj);
      break;
  }

}

Hhhmmm.. i think, this my trick.. :~ As we know, to process something is based on FIFO (First In, First Out). So, if one client want to use "ReceiveDataStatic" first, the message that is reveived by this method will be processed as early as possible. And how, if other client using other method, mmm.. we assume they use "ReceiveDataInvestor" method at the same time?? Is this thread can run at the same time (we must remember about FIFO)?? (i mean that 2 threads can run simultaneously.)

Is there any suggestion or the best way for this problem..?? help me please.. :confused:
Posted

Your coding has some fundamental problem. You cannot really spawn new threads from a web method and utilize that effectively.

When a request arrives at an Asp.net application, a single thread is picked by the Asp.net runtime from the thread pool to serve this particular request and once the request is served, the thread dies. Internally, a web service method is also a web request and hence a single Thread is also taken from the thread pool to execute the web method and once the method invocation is done, the thread dies as usual.

Now, if you spawn one or more child threads from within the web service method, it's not guaranteed that these threads can complete their work because the parent thread (The thread that is serving the current request) may die already. If the parent thread dies, the child threads will be dead immediately without finishing their work.

So, you actually shouldn't use threading from within a Web service method :)
 
Share this answer
 
Comments
Teamsar Muliadi 30-Aug-10 1:07am    
Hhhmm... i see.. :) but, how about "peformance" and "bottleneck" guru ??
You should try to optimize your processing as much as possible. No alternative :)

Best of luck.
 
Share this answer
 
Comments
Teamsar Muliadi 30-Aug-10 2:51am    
Mmm.. ok.. :) thank you guru.. :)
Teamsar Muliadi 30-Aug-10 2:57am    
Btw, what is the difference between "asynchronous thread" and "not asynchronous" guru..?? And how about "Thread Join" ?? would u tell me..??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900