Main Page | Report this Page
.NET DotNet Forum Index  »  .NET Framework Forum  »  Object Pooling in Background Thread 3.5 Sample?...
Page 1 of 1    

Object Pooling in Background Thread 3.5 Sample?...

Author Message
SnapDive...
Posted: Wed Oct 14, 2009 1:24 pm
Guest
I would like to instance 20 objects (not kidding about the number) on
background threads and then issue asynchronous method calls to them.
They do not need to send anything back to the caller. If one of the
instances hangs then I would like to know.

Can anyone point me to some sample C# 3.5-SP1 framework stuff that
will do that?


Thanks.
 
Peter Duniho...
Posted: Wed Oct 14, 2009 2:11 pm
Guest
SnapDive wrote:
Quote:

I would like to instance 20 objects (not kidding about the number) on
background threads and then issue asynchronous method calls to them.
They do not need to send anything back to the caller. If one of the
instances hangs then I would like to know.

Can anyone point me to some sample C# 3.5-SP1 framework stuff that
will do that?

First, it would be helpful if you could be more clear about what you're
trying to do.

Do you have one more more background threads, during the execution of
which you want to instantiate new objects, which will themselves operate
asynchronously?

Or will these objects simply be used from within the background threads
you already have?

Or do you intend on having yet another object somewhere responsible for
executing asynchronously, and which calls methods in your
newly-instantiated objects?

For samples, MSDN has a number of code examples as part of the various
threading documentation pages. For example, the Thread class, the
ThreadPool class, the BackgroundWorker class, etc.

By the way, no one would think you are kidding about creating 20
objects. That's hardly a large number of objects for an OO program to
be using.

Pete
 
Gregory A. Beamer...
Posted: Thu Oct 15, 2009 10:33 am
Guest
SnapDive <SnapDive at (no spam) community.nospam> wrote in
news:j39cd5t0u1bd5s8rpgir7m771o5ifv2t5t at (no spam) 4ax.com:

Quote:
I would like to instance 20 objects (not kidding about the number) on
background threads and then issue asynchronous method calls to them.
They do not need to send anything back to the caller. If one of the
instances hangs then I would like to know.

So you have 20 calls at one time that are necessary for a single
process? Or are you trying to rewrite the thread pool in a custom
manner?

Spinning up threads and determining if there is an error is quite easy
in .NET with event handlers. And I see nothing particularly incidious
about 20 threads running in a .NET application.

The issue I see is if you are opening 20 threads and then leaving them
open for when you need to run processes, as this can be accomplished
through a thread pool without writing your own custom pool.

I guess the question is "what is the problem you are trying to solve?"
and not "How do I solve the problem THIS way?"

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: at (no spam) gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
SnapDive...
Posted: Fri Oct 16, 2009 11:30 am
Guest
Currently the console app (can be optionally launched as a Win32
service) subscribes to a wcf evemt. When it gets a message, it does a
switch to pick/instance 1 of 20 objects that does regex and other
string manipulation. Usually its fast but 1-2 of the objects can hang
or take 10+ minutes to work because the regex won't handle the input
cleanly; neither case is acceptable. It would be cool if the regex had
a timeout overload, but it doesn't. Regex expressions are volatile and
fragile, so one that is good now may hang later (this processes kinds
of textual citations from documents).

So, why not just instance all 20 objects and put them in a pool, when
one is needed use it on a background thread? That way when one "goes
bad", processing can continue from the main app.

The server this runs on is pretty busy, and with a finite number of
CLR threads, I thought it'd be better for the app to have its own
instead of sharing with other apps.

Thanks.




On Thu, 15 Oct 2009 09:33:25 -0700, "Gregory A. Beamer"
<NoSpamMgbworld at (no spam) comcast.netNoSpamM> wrote:

Quote:
SnapDive <SnapDive at (no spam) community.nospam> wrote in
news:j39cd5t0u1bd5s8rpgir7m771o5ifv2t5t at (no spam) 4ax.com:

I would like to instance 20 objects (not kidding about the number) on
background threads and then issue asynchronous method calls to them.
They do not need to send anything back to the caller. If one of the
instances hangs then I would like to know.

So you have 20 calls at one time that are necessary for a single
process? Or are you trying to rewrite the thread pool in a custom
manner?

Spinning up threads and determining if there is an error is quite easy
in .NET with event handlers. And I see nothing particularly incidious
about 20 threads running in a .NET application.

The issue I see is if you are opening 20 threads and then leaving them
open for when you need to run processes, as this can be accomplished
through a thread pool without writing your own custom pool.

I guess the question is "what is the problem you are trying to solve?"
and not "How do I solve the problem THIS way?"

Peace and Grace,
 
Gregory A. Beamer...
Posted: Mon Oct 19, 2009 12:18 pm
Guest
SnapDive <SnapDive at (no spam) community.nospam> wrote in
news:piahd5l96p6o46af2apafhdjafae3b3qpr at (no spam) 4ax.com:

Quote:
So, why not just instance all 20 objects and put them in a pool, when
one is needed use it on a background thread? That way when one "goes
bad", processing can continue from the main app.

I will have to take some time to mull this over, but it appears sound on
the surface.

Jon Skeet created a custom thread pool, if that might help:
http://www.yoda.arachsys.com/csharp/miscutil/

It is at least worth a shot.

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: at (no spam) gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
SnapDive...
Posted: Tue Oct 20, 2009 9:52 pm
Guest
I'll check out the link.

Did you have time to mull things over, Gregory?


Thanks.


On Mon, 19 Oct 2009 11:18:43 -0700, "Gregory A. Beamer"
<NoSpamMgbworld at (no spam) comcast.netNoSpamM> wrote:

>http://www.yoda.arachsys.com/csharp/miscutil/
 
Gregory A. Beamer...
Posted: Thu Oct 22, 2009 9:17 am
Guest
SnapDive <SnapDive at (no spam) community.nospam> wrote in
news:ca1td5h5i5t74k4908kkhmonmprme9r5hm at (no spam) 4ax.com:

Quote:

I'll check out the link.

Did you have time to mull things over, Gregory?

I did not have time to realy go through it, but I still have come up with
no overwhelming reason not to set up a thread pool. And I trust Jon Skeets
work, if that will help you get started.

It has been crazy for me lately <g>

Peace and Grace,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: at (no spam) gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Wed Dec 02, 2009 9:20 pm