Recursive Call

S

slg

Gurus, I have a Winform which has a button. When the button click function
creates a thread.

I want the thread to call the button click again . I can have only one
instance of the
thread running at a time.

I want to automate testing of my function.
Any thoughts.

TIA

private void btnProcessFiles_Click(object sender, EventArgs e)
{

Thread trd = new Thread(new ThreadStart(this.ThreadedProcessFiles));
trd.IsBackground = true;
trd.Start();
}
void ThreadedProcessFiles()
{
// how can i call btnProcessFiles_Click
}
 
J

Jon Skeet [C# MVP]

slg said:
Gurus, I have a Winform which has a button. When the button click function
creates a thread.

I want the thread to call the button click again . I can have only one
instance of the thread running at a time.

I want to automate testing of my function.

It's not clear to me why you want to call the button click if you only
want to have one thread running at a time. Could you give more context?
 
M

Mugunth

It's not clear to me why you want to call the button click if you only
want to have one thread running at a time. Could you give more context?

UI Methods are not thread safe. Calling a UI Operation from a thread
will give you a runtime exception.
Try a BackgroundWorker (http://msdn2.microsoft.com/en-us/library/
system.componentmodel.backgroundworker.aspx). Also can you be a bit
more clear?
Mugunth
 
J

Jon Skeet [C# MVP]

Mugunth said:
UI Methods are not thread safe. Calling a UI Operation from a thread
will give you a runtime exception.

True - but calling the button click *handler* would be okay. It's not
clear there are any actual UI operations required here.
 
M

Marc Gravell

You want to simulate pressing the button?
Well, it could call someButton.PerformClick()? (making sure to switch back
to the UI thread first - thread-affinity 'n'all).
i.e. theButton.BeginInvoke((MethodInvoker)theButton.PerformClick);

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top