-
threads and singleton objects
If I have a singleton object that is created when a .NET web application is started and then I spawn a new thread from that application, can the child thread see and use the singleton object?
Laurence -
-
I believe so. Basically you want to know if you create an object on one thread can another thread use it. I've done this without a problem. The only thing to consider is possible syncronization issues. If any possible issues exist they'll need to be taken care of some how.
-
Also remember that if the singleton is a form, then you need to use Invoke / BeginInvoke if you are gonna do any GUI-work from the other thread.
oes
-
What I'm going to trying to do is store used command objects within a collection contained within the singleton object. The thread is there to monitor the singleton object and remove command objects that aren't used within a given amount of time (to prevent what could be a massive memory leak).
I figure that way, I'll save the time required to constantly recreate and configure command objects for those stored procedures that are most commonly used by the application as it runs.
Laurence -
-
Threading does not affect scope, so as long as the singleton object can be seen by the thread routine, you are OK.
If you will have multiple threads accessing the object, make sure you read up on syncronization and possible issues.
Similar Threads
-
By hemanthjava in forum Java
Replies: 2
Last Post: 11-14-2006, 10:57 PM
-
By Gwyn Carwardine in forum .NET
Replies: 0
Last Post: 04-29-2002, 10:01 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks