Threading Problem

  • Thread starter Thread starter Abdul Rahman
  • Start date Start date
A

Abdul Rahman

Hi,
I am using a API to access a Datasource in a Web
Application.The API is purely single threaded.
When there are more than one user trying to access the
data.the API crashes and this inturn kills the ASpnet
worker process.

Can anybody help me out with how to proceed to write a
Wrapper class so that i can achieve crash free experience.

Any help will be highly appreciated

Regards
Abdul Rahman
 
The easiest option would be to wrap the single-thread object in a .NET
object that was thread-safe:

public class DataSourceWrapper{
private static object _dataSource = new DataSource();
public static void UseDataSource( /*add required params here*/){
lock(typeof(DataSourceWrapper)){
//code to use _dataSource here;
}
}
}

If the single-threaded API is used to service a lot of requests, there will
be a significant performance and scalability problem on the site.

Nick Wienholt, MVP
Maximizing .NET Performance
http://www.apress.com/book/bookDisplay.html?bID=217
Sydney Deep .NET User Group www.sdnug.org
 
General idea is
- move ALL single-threaded code and objects into thread body
- don't reference single-threaded objects and code from outside enclosing
thread

Rationale: for simplicity sake you can consider thread as separate process.
If you can run 2 and more instances of your application without crashes
chances are you can use API in multi-threading mode. If you can't do this,
your API is really not suitable for threading.

HTH
Alex
 
Back
Top