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

  • Home
  • SEARCH
  • 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 8263267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:02:27+00:00 2026-06-08T04:02:27+00:00

i would like to block a function and wait for an event then continue

  • 0

i would like to block a function and wait for an event then continue , in my case the pseudo-code that i want to have when i click a button:

  • pop up messagebox
  • wait for the event click in datagridview
  • pop up messagebox2
  • wait for the event click in datagridview
  • pop up a yes/no messagebox
  • execute another function

but the actual code do not wait for autoevent.Set() function so the functions called by the threads remains blocked while i want to block the main function.

i tried ManualResetEvent and AutoResetEvent, this is the code that i used for AutoResetEvent :

 public partial class person : Form
    {

AutoResetEvent auto = new AutoResetEvent(false);  

private void button1_Click(object sender, EventArgs e)
        {
           int old_id, new_id;

            //dataGridView1.ClearSelection(); 
            Thread t1 = new Thread(new ThreadStart(th_remove));
            Thread t2 = new Thread(new ThreadStart(th_replace));

            t1.Start(); 
           old_id = (int)dataGridView1.SelectedRows[0].Cells[1].Value; 

           t2.Start();
           new_id = (int)dataGridView1.SelectedRows[0].Cells[1].Value;

            DialogResult dialogResult = MessageBox.Show("Remplacer", "Vous êtes sûr de vouloir remplacer ?", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                db.replace("person", new_id, old_id); 
            }
           }

        private  void th_replace()
        {
            auto.WaitOne();  
            MessageBox.Show("Seléctionnez la ligne remplaçante");
        }

        private  void th_remove()
        {
            auto.WaitOne();          
            MessageBox.Show("Seléctionnez la ligne à supprimer");
        }


        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
             auto.Set();
        }
    }

Thanks in advance

  • 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-08T04:02:28+00:00Added an answer on June 8, 2026 at 4:02 am

    You could try to add a synchronization object and use Monitor’s methods Wait and Pulse on your sync object. That is you need to call Pulse in your event handler and Wait in your synchronous method. But make sure your event does not occur before you enter the Wait state… =)
    Good luck!

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

Sidebar

Related Questions

i would like to have a block on my drupal site(latest version) that displays
I have a function like this, that I would like to refactor function Myfunction(sUrl,
I'm looking to create something like in this image. Each block would have an
I have a text field entry in my view that I would like to
Say I have function with_foo that takes a block, and wrap it around a
I would like to have a function which get start_day and end_day as two
I would like a block that display slide show on left side for certain
(category==Villor/Radhus mm)?byId(nav_sub_villor).style.display='block' : byId(nav_sub_villor).style.display='none'; I would like to call a function if the statement
i would like to be able to click a link and have a form
I've got this code: $('a').click( function() { $(#change_flash).css(display, block); $(#my_flash).css(display, none); }); But this

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.