I am having great difficulty understanding this and any code samples I find
online are kilometres long and complicated to understand...Pl ease could
someone give me a simple exampe of how to get a delegate passed to my worked
class so that my main form can update its progress bar? I know it has
something to do with begininvoke and endinvoke etc, but I just need a simple
sample to understand the convention.
Code from my main form:
-----------------------------------
form1Delegate dlgate = new form1Delegate(I ncreaseProgress Bar);
//thing.countUpTo aMillionOrSomet hing(new
form1Delegate(t his.IncreasePro gressBar));
Thread thread = new Thread(new
ThreadStart(thi ng.countUpToaMi llionOrSomethin g(dlgate)));
thread.Start();
-----------------------------------
Code from my worker class called 'thing'
-----------------------------------
public static void countUpToaMilli onOrSomething(F orm1.form1Deleg ate
myMethodDelegat e)
{
int x = 0;
while ( x < 50)
{
Thread.Sleep(70 );
x ++ ;
myMethodDelegat e();
}
}
-----------------------------------
I can only get it to work synchronously with the following line:
thing.countUpTo aMillionOrSomet hing(new
form1Delegate(t his.IncreasePro gressBar));
If I try compile with the thread example above it spews about 'Method name
expected' and underlines the following bit of code:
thing.countUpTo aMillionOrSomet hing(dlgate)
Any help greatly appreciated,
Thanks,
Grant
online are kilometres long and complicated to understand...Pl ease could
someone give me a simple exampe of how to get a delegate passed to my worked
class so that my main form can update its progress bar? I know it has
something to do with begininvoke and endinvoke etc, but I just need a simple
sample to understand the convention.
Code from my main form:
-----------------------------------
form1Delegate dlgate = new form1Delegate(I ncreaseProgress Bar);
//thing.countUpTo aMillionOrSomet hing(new
form1Delegate(t his.IncreasePro gressBar));
Thread thread = new Thread(new
ThreadStart(thi ng.countUpToaMi llionOrSomethin g(dlgate)));
thread.Start();
-----------------------------------
Code from my worker class called 'thing'
-----------------------------------
public static void countUpToaMilli onOrSomething(F orm1.form1Deleg ate
myMethodDelegat e)
{
int x = 0;
while ( x < 50)
{
Thread.Sleep(70 );
x ++ ;
myMethodDelegat e();
}
}
-----------------------------------
I can only get it to work synchronously with the following line:
thing.countUpTo aMillionOrSomet hing(new
form1Delegate(t his.IncreasePro gressBar));
If I try compile with the thread example above it spews about 'Method name
expected' and underlines the following bit of code:
thing.countUpTo aMillionOrSomet hing(dlgate)
Any help greatly appreciated,
Thanks,
Grant
Comment