Help with a "Basic" C# thread
Posted on 2005-04-01
I'm trying to write a very simple thread in C#. I can get most of it working, but I can't get the thread to pass back information to the calling form as it runs. I can't find a decent example of what I need. If I could get a simple example, I could learn from it. Here's what I'd like...very simple.
1 form. It would contain 3 buttons ("cmdRun", "cmdPause", and "cmdResume") and 1 text box ("txtInfo").
1 class containing a method "CreateFile" that would create and write 1,000,000 lines to a text file. (To ensure it takes a few seconds to run).
When the "cmdRun" button is clicked, it would run the "CreateFile" method in a thread. As each line is written to the file (From the CreateFile Method), I would like to have the line number displayed in the text box on the main form. (So I would see it increment from 1 - 1,000,000. This is the main part I'm stuck on).
Also, at any time, I'd like to be able to click the "Pause" and resume buttons, and if possible, I'd like the location of the file to be created to be specified in the "cmdRun" button, not hard coded into my class.
I'll give a starting amount of 200 points for an example that does all of these things (Note: I may have to ask a few questions until I'm sure I understand it). Then, I may post a few follow up questions if I wish to "enhance" the project with a few extras, but I'll give separate points/questions for follow ups.
Good luck, and Thanks so much! I've been stuck on this problem all week...