Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Recursive Call

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
slg - 29 Feb 2008 12:36 GMT
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
}
Jon Skeet [C# MVP] - 29 Feb 2008 12:39 GMT
> 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

Marc Gravell - 29 Feb 2008 14:11 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.