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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:03:06+00:00 2026-05-20T18:03:06+00:00

foreach (KeyValuePair<int, int[]> item in replay)// count should be more than 2 { makeSelfMoves

  • 0
       foreach (KeyValuePair<int, int[]> item in replay)// count should be more than 2
        {           
            makeSelfMoves = replay[item.Key];
            codeFile.ExecuteAll(makeSelfMoves[0], makeSelfMoves[1], makeSelfMoves[2], makeSelfMoves[3]);
            PrintPieces(codeFile.PieceState());
            // MessageBox.Show("rowStart: " + makeSelfMoves[0] + ". rowEnd: " + makeSelfMoves[2] + ". columnStart: " + makeSelfMoves[1] + ". columnEnd: " + makeSelfMoves[3] + "____a is: " + a);

        }

i want to execute this whole iteration, that i responsible for a game replay, in 1 second intervals. i put a timer in my form and set it to 1 second (this should make the pieces to be moved at 1 second intervals). i made an event, and before the loop i put the statement, timer1.enabled=true. The iteration will reach the end in a quick manner.. how do you use a timer to set iteration to execute each second using the timer?


  public void ReplayGame()
    {
        Class2.replayIsOn = true;
        replay=serializeMeh.giveBackDictionary();
        int[] makeSelfMoves=new int[4];


        //Timer t = new Timer();
        //t.Interval = 1000;
        //t.Tick += timer1_Tick;
        //t.Enabled = true;
        //t.Start();
        if (backgroundWorker1.IsBusy != true)
        {
            // Start the asynchronous operation.
            backgroundWorker1.RunWorkerAsync();
        }

        //foreach (KeyValuePair<int, int[]> item in replay)// count should be more than 2
        //{


        //    makeSelfMoves = replay[item.Key];
        //    codeFile.ExecuteAll(makeSelfMoves[0], makeSelfMoves[1], makeSelfMoves[2], makeSelfMoves[3]);
        //    PrintPieces(codeFile.PieceState());


        //    MessageBox.Show("rowStart: " + makeSelfMoves[0] + ". rowEnd: " + makeSelfMoves[2] + ". columnStart: " + makeSelfMoves[1] + ". columnEnd: " + makeSelfMoves[3] );

        //}


    }

The above method is activated if i want a replay.

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker worker = sender as BackgroundWorker;

        int[] makeSelfMoves = new int[4];

        foreach (KeyValuePair<int, int[]> item in replay)// count should be more than 2
        {
            makeSelfMoves = replay[item.Key];// delivers an array of a single move location startrow,startcolumn,endrow,endcolun
            codeFile.ExecuteAll(makeSelfMoves[0], makeSelfMoves[1], makeSelfMoves[2], makeSelfMoves[3]);
            PrintPieces(codeFile.PieceState());// prints the code on the board

            System.Threading.Thread.Sleep(1000);
        }

    }

it does the work, but the problem that i had is after the loop finishes, the pieces that existed disappear. is it because of the background worker, cause without it , i have no pieces disappear at the end of the process. The second time that i activate the method, it happens

  • 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-20T18:03:06+00:00Added an answer on May 20, 2026 at 6:03 pm

    Run it in a background thread and put Thread.Sleep(1000) in the loop.

    This way it will be time based and not freeze your app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

.NET 2 The standard: foreach(KeyValuePair<int,int> entry in MyDic) { entry.Value += i; // does
Imagine that during a foreach(var item in enumerable) The enumerable items change. It will
Currently I am using a Dictionary<int,node> to store around 10,000 nodes. The key is
I refactored my foreach loop from this before: foreach (KeyValuePair[string, string] param in paramsList)
Basically, the equivalent of this: public static IEnumerable<KeyValuePair<int, T>> Enumerate<T>(this IEnumerable<T> enumerable) { int
List<CormantRadPane> panesToSave = new List<CormantRadPane>(); foreach (KeyValuePair<string, RadPaneSetting> paneState in RadControlStates.PaneStates) { CormantRadPane pane
I have two Dictionary<string, Item> s. Item has a has a public property int
Alright, I'm trying to pass a Dictionary, where key = int, and value =
I have this little piece of code : private Dictionary<string, IList<KeyValuePair<int, string>>> EnumsCollection =
foreach ($_GET as $field => $label) { $datarray[]=$_GET[$field]; echo $_GET[$field]; echo <br>; } print_r($datarray);

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.