Well the code I presented displayed how the communication should operate
without encountering thready badness.
A more complete example would be:
class Form1:Form
{
public delegate void StringDelegate( string message);
public void ThreadSafeUpdat eText(string message)
{
this.BeginInvok e(new StringDelegate( UpdateText), new
object[]{message});
}
private void UpdateText(stri ng message)
{
this.Text = message;
}
private void btn_Click(objec t sender, EventArgs e)
{
KillerObject killer = new KillerObject(th is);
killer.DoSometh ingRockin();
}
}
public class KillerObject
{
Form1 form;
public KillerObject(Fo rm1 form)
{
this.form = form;
}
public void DoSomethingRock in()
{
for(int i = 0; i< 100; i++)
{
form.ThreadSafe UpdateText("Cur rently looping: " + i.ToString());
}
}
}
Obviously you'd need to change the code to use a progress bar and it might
be better for the killer object to use events instead of taking a reference
to the form.
Additionally if you wanted to keep the UI active it would be best to run
"DoSomethingRoc kin" in a seperate thread.
HTH.
Simon Tamman
"sherifffruitfl y" <sh************ *@gmail.comwrot e in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
>
Simon Tamman wrote:
(code snipped)
The above code will update the title of a given form without locking up
in
thread hanging badness.
I guess I just don't understand - it looks to my eye as though the
class (of the object) that's doing the stuff doesn't have any
"communicat ion code" in your (and everyone else's) examples? How on
earth does the form know what's going on with the object, if the object
doesn't have any code "telling" the form what's going on?
I was probably unclear about what I'm dealing with. Here's a minimal
"template" example:
public class myform : system....form
{
.
.
.
private void btn_awesomeButt on_Click(object sender, System.EventArg s e)
{
killerObject ko = new killerObject;
ko.doSomethingR ockin();
}
}
public class killerObject
{
.
.
.
public doSomethingRock in()
{
(loop to delete 1000 hardcoded files here)
}
}
What I want to do is have the status bar (or any control) on the form
be updated every pass thru the loop in the object created by the button
click event (say with the name of the file being deleted).
Does that make sense even? Does your suggestion suffice for what I'm
after? I would've thought that some code would have had to have been
added to killerObject *as well as* to the form.
thanks for the replies all! sorry if I was unclear...