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 8069025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:52:47+00:00 2026-06-05T12:52:47+00:00

here i am trying to generate a dynamic threads by reading xml document for

  • 0

here i am trying to generate a dynamic threads by reading xml document for each attribute id,but am facing a problem that how to pass parameter to dynamic thread,for which related elements of the particular attribute, is there any way to send parameters? please advice

in below thread i am calling a dowork method, i have to pass parameters of elements of which particular attribute id how can i do that?

static void Main(string[] args)
{
var currentDir = Directory.GetCurrentDirectory();
var xDoc = XDocument.Load(string.Format(Path.Combine(currentDir, "Hosts.xml")));
var threads = new List<Thread>();

foreach (XElement host in xDoc.Descendants("Host"))
{
    var hostID = (int) host.Attribute("id");
    var extension = (string) host.Element("Extension");
    var folderPath = (string) host.Element("FolderPath");
    var thread = new Thread(DoWork)
                     {
                         Name = string.Format("samplethread{0}", hostID)
                     };
    thread.Start(new FileInfo
                     {
                         HostId = hostID,
                         Extension = extension,
                         FolderPath = folderPath
                     });
    threads.Add(thread);
    }
   //Carry on with your other work, then wait for worker threads
   threads.ForEach(t => t.Join());
}

   static void DoWork(object threadState)
     {
       var fileInfo = threadState as FileInfo;
            if (fileInfo != null)
             {
               //Do stuff here
             }
      }

      class FileInfo
         {
           public int HostId { get; set; }
           public string Extension { get; set; }
           public string FolderPath { get; set; }
         }

How do I call a method that takes multiple parameters in a thread. I have a method called

 Send(string arg1, string arg2, string arg3)

thats the reason i have asked you guys for any solution to pass parameters,note here my threading methodology was designed by dynamical manner, any suggestion please ?

  • 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-06-05T12:52:49+00:00Added an answer on June 5, 2026 at 12:52 pm

    You’re already passing in parameters just fine. I’m not sure if I understand your question but

    i have to pass parameters of elements of which particular attribute id
    how can i do that?

    It sounds like all you need is an if statement inside your foreach. You are already looping through and creating threads/passing params. Are you just asking how to make sure each item has a particular attribute id? If so – just make it

    foreach (XElement host in xDoc.Descendants("Host"))
    {
        var hostID = (int) host.Attribute("id");
        // Check ID here
        if(hostID != ID_I_WANT) 
            continue;
        var extension = (string) host.Element("Extension");
        var folderPath = (string) host.Element("FolderPath");
        var thread = new Thread(DoWork)
                         {
                             Name = string.Format("samplethread{0}", hostID)
                         };
        thread.Start(new FileInfo
                         {
                             HostId = hostID,
                             Extension = extension,
                             FolderPath = folderPath
                         });
        threads.Add(thread);
        }
       //Carry on with your other work, then wait for worker threads
       threads.ForEach(t => t.Join());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to generate a RDoc using the XML format. Here's the command that
So here is the problem: I am trying to create dynamic buttons that have
I'm trying to pass context into a dynamic expression that I evaluate every iteration
I'm trying to generate a bunch of random numbers using rand() % (range). Here's
As I mentioned here , I'm trying to generate HTML from an ASPX page
I know of the ||= operator, but don't think it'll help me here...trying to
Noob dumb question, no doubt -- but here it is: Trying to tutorialize myself
I can generate the controls but can't remove them. I'm trying to add a
Here is my situation... I am trying to dynamically generate a bunch of stuff
I know I'm breaking some rules here with dynamic SQL but I still need

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.