Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7023385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:42:15+00:00 2026-05-27T23:42:15+00:00

Afternoon, evening… whatever it is where you are ;) I’m working on a ‘ThreadManager’

  • 0

Afternoon, evening… whatever it is where you are 😉

I’m working on a ‘ThreadManager’ that will execute a set of ‘ManagedThread<>’s. A managed thread is a generic wrapper for a ‘ManagableThread’, which contains most of the essential methods.

The list of ‘ManagableThread’s to start up, is based on what comes out of a configuration file, and is generated in the ThreadManager.Start method. This list, is meant to be populated with all of the ‘ManagedThread’s that are to be… managed. Here is the code that I am trying to use to complete this task, and as I’m sure any competent C# developer will quickly realize – I’m not gonna swing it like this.

public void Start() {
    foreach (String ThreadName in this.Config.Arguments.Keys) {
        Type ThreadType = null;

        if ((ThreadType = Type.GetType(ThreadName)) == null) {
            continue;
        }
        else {
            ManagedThread<ThreadType> T = new ManagedThread<ThreadType>(
                this,
                this.GetConfiguration(ThreadType)
            );
            this.ManagedThreads.Add(T);

            continue;
        }
    }
}

I’ve taken a few stabs at this to no avail. If anyone has any suggestions I’d appreciate them. I’m no Generics expert, so this is slightly out of my realm of expertise, so please do refrain from making me cry, but feel free to catch me if I’m a fool.

Thanks in advance to anyone who can offer a hand.

Edit: I suppose I should clarify my issue, rather than make you all figure it out… This code will not compile as I cannot pass ‘ThreadType’ to the generic parameter for my constructor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:42:16+00:00Added an answer on May 27, 2026 at 11:42 pm

    That doesn’t make sense.
    Generics are compile-time types; you can’t have a compile-time type that isn’t known until runtime.

    Instead, you need to use Reflection:

    Type gt = typeof(ManagedThread<>).MakeGenericType(ThreadType);
    object t = Activator.CreateInstance(gt, this,this.GetConfiguration(ThreadType));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good morning, afternoon, evening or night (depending on your timezone). This is just a
Afternoon Developers, I have a problem that's beginning to get on my wick. I
This afternoon, upon noticing a broken build and the fact that some files looked
Afternoon, I have been working with CKEditor and CKFinder for the last few days
afternoon all. Iv'e come across some mathematical problems that im not too good at.
Afternoon. I am currently working a drink search site and started work on adding
Good afternoon all, I was wondering why is it that android.app.Activity.onTrimMemory couldn't be overridden?
Afternoon all. I've recently been tasked with working on an event-based support ticket system,
Good morning/afternoon/evening. I want to get automatic hyphenation placement in a BibTeX (with babel).
Good Afternoon, I have a html aspx page that has many many div elements.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.