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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:04:29+00:00 2026-05-28T05:04:29+00:00

This is a project I’m doing for my own amusement. I started out wanting

  • 0

This is a project I’m doing for my own amusement.

I started out wanting to experiment with combination and permutations. In a console application I have the following code

    public static void Save(string newWord)
    {
        using (var db = new MyDataContext())
        {
            var w = new Word {word = newWord};
            db.Words.InsertOnSubmit(w);
            db.SubmitChanges();
        }
    }

    static void Main(string[] args)
    {
        var letters = new[] { 'A', 'B', 'C', '1', '2', '3'};

        for (var i = 2; i < 10; i++)
        {
            letters.GetPermutations(a => Save(string.Join(string.Empty, a.ToArray())), i, true);
        }
    }

In an extension class, I have the code to generate the combinations. I found the code for the combinations here (http://blog.noldorin.com/2010/05/combinatorics-in-csharp/) for those wanting to review that.

    public static void GetCombinations<T>(this IList<T> list, Action<IList<T>> action, int? resultSize = null, bool withRepetition = false)
    {
        if (list == null)
            throw new ArgumentNullException("list");
        if (action == null)
            throw new ArgumentNullException("action");
        if (resultSize.HasValue && resultSize.Value <= 0)
            throw new ArgumentException(errorMessageValueLessThanZero, "resultSize");

        var result = new T[resultSize.HasValue ? resultSize.Value : list.Count];
        var indices = new int[result.Length];

        for (int i = 0; i < indices.Length; i++)
            indices[i] = withRepetition ? -1 : indices.Length - i - 2;

        int curIndex = 0;

        while (curIndex != -1)
        {
            indices[curIndex]++;

            if (indices[curIndex] == (curIndex == 0 ? list.Count : indices[curIndex - 1] + (withRepetition ? 1 : 0)))
            {
                indices[curIndex] = withRepetition ? -1 : indices.Length - curIndex - 2;
                curIndex--;
            }
            else
            {
                result[curIndex] = list[indices[curIndex]];
                if (curIndex < indices.Length - 1)
                    curIndex++;
                else
                    action(result);
            }
        }
    }

Then I thought it would be cool to calculate the combinations for all charaters in a list, each in its own thread. So in my for/next loop, I tried

Thread t = new Thread(letters.GetPermutations(a => Save(string.Join(string.Empty, a.ToArray())), i, true));

But apparently, the Action that is being passed in, the call to the ‘Save’ function, is not liked in the Thread. If someone could give me a nudge in the right direction, I’d appreciate it.

Thanks,
Andy

  • 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-28T05:04:30+00:00Added an answer on May 28, 2026 at 5:04 am

    The Thread constructor is looking for a delegate but you’re appearing to pass a value instead. Try wrapping it in an ThreadStart delegate.

    ThreadStart del = () => letters.GetPermutations(a => Save(string.Join(string.Empty, a.ToArray())), i, true);
    Thread t = new Thread(del);
    t.Start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this project that recently started crashing on beta builds of Windows 7.
This project started as a development platform because i wanted to be able to
I have found this project on Codeplex. http://www.codeplex.com/ProjNET I need to integrate this code
I have this project that i need to add a translation to. I already
I have a project folder like this: project/ cow/ a.java horse/ b.java both a.java
For this project, I have to have it so that the page loads while
I'm doing this project to manage a bank and I'm trying to implement code
I used this project to simulate the bluetooth on android emulator. I have 2
I started this project a long long time ago when I was just beginning
my project is a PHP web application. This applies to my test server (local),

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.