473,322 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Dynamic creation of worker threads

Hi,

My project will have a number of classes all implementing a single
interface, e.g.

class A : IA
class B : IA
class C : IA
(etc)

Given a list of class names (from a config file, e.g. a string[] = {"A",
"B", "C"}), how could I dynamically start each one as a separate thread?

Thanks!!
Alex
Nov 17 '05 #1
4 4240
Alex wrote:
My project will have a number of classes all implementing a single
interface, e.g.

class A : IA
class B : IA
class C : IA
(etc)

Given a list of class names (from a config file, e.g. a string[] = {"A",
"B", "C"}), how could I dynamically start each one as a separate thread?


Well, you can't "start" a class, but you could fairly easily run a
method specified in IA in a separate thread:

1) Use reflection to create the instances.
2) For each instance, create a new ThreadStart delegate targetting an
IA method acting on the instance
3) For each of the delegates, create a new thread and start it.

I suspect you're stuck on one of those steps, but it's hard to say
which - if you could elaborate, I'm sure we can help further.

Jon

Nov 17 '05 #2
Alex wrote:
My project will have a number of classes all implementing a single
interface, e.g.

class A : IA
class B : IA
class C : IA
(etc)

Given a list of class names (from a config file, e.g. a string[] = {"A",
"B", "C"}), how could I dynamically start each one as a separate thread?


Well, you can't "start" a class, but you could fairly easily run a
method specified in IA in a separate thread:

1) Use reflection to create the instances.
2) For each instance, create a new ThreadStart delegate targetting an
IA method acting on the instance
3) For each of the delegates, create a new thread and start it.

I suspect you're stuck on one of those steps, but it's hard to say
which - if you could elaborate, I'm sure we can help further.

Jon

Nov 17 '05 #3
Jon,

Thanks for your prompt reply. I should have added that one of the interface
methods is called "start" - so I guess I was describing it in my terms...
that would be the method to call when

I'm able to create the instances using reflection, it's the threading that's
confusing me. Are there any samples/documentation I could look at to figure
this out?

Thanks,
Alex
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Alex wrote:
My project will have a number of classes all implementing a single
interface, e.g.

class A : IA
class B : IA
class C : IA
(etc)

Given a list of class names (from a config file, e.g. a string[] = {"A",
"B", "C"}), how could I dynamically start each one as a separate thread?


Well, you can't "start" a class, but you could fairly easily run a
method specified in IA in a separate thread:

1) Use reflection to create the instances.
2) For each instance, create a new ThreadStart delegate targetting an
IA method acting on the instance
3) For each of the delegates, create a new thread and start it.

I suspect you're stuck on one of those steps, but it's hard to say
which - if you could elaborate, I'm sure we can help further.

Jon

Nov 17 '05 #4
If you have the object than you can call:

ThreadStart ts = new ThreadStart(iaObject.start);
Threat t = new Thread(ts);
t.Start();

This will start the start method of your object on a seperate thread. Is
that what you had in mind?

saso

"Alex" <no****@hotmail.com> wrote in message
news:43***********************@news.zen.co.uk...
Jon,

Thanks for your prompt reply. I should have added that one of the
interface methods is called "start" - so I guess I was describing it in my
terms... that would be the method to call when

I'm able to create the instances using reflection, it's the threading
that's confusing me. Are there any samples/documentation I could look at
to figure this out?

Thanks,
Alex
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Alex wrote:
My project will have a number of classes all implementing a single
interface, e.g.

class A : IA
class B : IA
class C : IA
(etc)

Given a list of class names (from a config file, e.g. a string[] = {"A",
"B", "C"}), how could I dynamically start each one as a separate thread?


Well, you can't "start" a class, but you could fairly easily run a
method specified in IA in a separate thread:

1) Use reflection to create the instances.
2) For each instance, create a new ThreadStart delegate targetting an
IA method acting on the instance
3) For each of the delegates, create a new thread and start it.

I suspect you're stuck on one of those steps, but it's hard to say
which - if you could elaborate, I'm sure we can help further.

Jon


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: fooooo | last post by:
This is a network app, written in wxPython and the socket module. This is what I want to happen: GUI app starts. User clicks a button to 'start' the work of the app. When start is pressed, a new...
0
by: Mike Meyer | last post by:
The recent thread on threads caused me to reread the formal definition of SCOOP, and I noticed something I hadn't really impressed me the first time around: it's using staticly checkable rules to...
1
by: Mark Hoffman | last post by:
All, From what I've read, the CLR gives each App Domain a thread pool of 25 threads, and once this pool is exhausted then any new threads created with BeginInvoke will block until the pool frees...
1
by: Harry F. Harrison | last post by:
Hi all... During startup of an ASP.NET app, I have code that dynamically goes out and loads assemblies, looking for objects that implement a particular interface. This code works fine, EXCEPT,...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
6
by: Joe Jax | last post by:
I have an object that spawns a worker thread to process one of its methods. That method processes methods on a collection of other objects. During this processing, a user may request to cancel the...
0
by: Gregory Gadow | last post by:
Still working on this project. What I have working: I have a service that uses FileSystemWatcher on an "in box" folder. When a text file appears in the in-box, it copies the file to a work...
3
by: Kevin | last post by:
Using this: http://msdn2.microsoft.com/en-us/library/3dasc8as(VS.80).aspx as an example I have a question concerning the reuse of objects. In the example 10 instances of the Fibonacci class...
3
by: =?Utf-8?B?Sm9obiBCYWlsZXk=?= | last post by:
I am currently evaluating a CMS product. I like the product so far, but one of the restrictions on the product is that it requires that the Windows 2003 application pool be restricted to one...
7
by: csharpula csharp | last post by:
Hello, I got a question regarding the usage of background worker. How can I run few threads via background worker with different objects as parameter each time. I understood that I can't do...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.