views:

619

answers:

3

In my application I want to suspend a button event for some time so that I can fire another event after which the first button event will resume. In c# I am not getting how do I perform it using threads asynchronously. Please help. Thanks in advance..

+2  A: 

If you want to fire the second event and wait for it to finish before continuing, then why not just fire it synchronously from within the first event handler? That would be much simpler.

EDIT:

If you want one button to trigger the code that's in another button's event handler, I would suggest instead that you move it out into a separate function, and just call that. In other words, do this:

private void button1_Click(object sender, EventArgs e)
{
    DoButtonStuff();
}

private void button2_Click(object sender, EventArgs e)
{
    DoButtonStuff();
}

private void DoButtonStuff()
{
    // code that was originally in button2_Click()
}

If the buttons do the exact same thing, you could even just assign them the exact same handler.

But, if you really must programmatically "click" a button, then the easiest way is probably:

button2.PerformClick();

That'll raise a Click event.

Andrew Watt
ya iam trying to do that I need some sample code for that. I need to know how to fire a button event within other event. But I dont know the parameters of the button event please provide sample code
Enjoy coding
+1  A: 

This sounds like a design problem in your application and you're tackling it from the wrong end.

Igor Brejc
A: 

could you do something with background worker

background worker bw = new background worker


button1

while bw.inprogress
{

//kill time

}
bw.(dosomething)



button2
{
while bw.inprogress
{
//killtime

}
bw.run(dosomething)
}
Crash893