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
}
> Gurus, I have a Winform which has a button. When the button click function
> creates a thread.
[quoted text clipped - 3 lines]
>
> 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?

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Mugunth - 29 Feb 2008 13:33 GMT
> > Gurus, I have a Winform which has a button. When the button click function
> > creates a thread.
[quoted text clipped - 10 lines]
> Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
> World class .NET training in the UK:http://iterativetraining.co.uk
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
Jon Skeet [C# MVP] - 29 Feb 2008 13:55 GMT
> 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.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
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