multithreading - C# Using a delegate to a member function to create a new thread -
i'd create new thread member function. use code,
thread thread = new thread(new threadstart(c.dosomethingelse)); thread.start();
and it's working. i'd parameterize member function.
i have class:
class c1 { public void dosomething() {} public void dosomethingelse() {} public delegate void mydelegate(c1 c); }
then have function in other class:
public void myfunction(c1.mydelegate func) { c1 c = new c1(); func(c); // working // want called function runs in it's own thread // tried... thread thread = new thread(new threadstart( func(c) ); // compile wants thread.start(); // method name , not delegate }
i call myfunction follows...
myfunction( (c) => c.dosomething() );
so possible this. mean, can pass delegate und call object func(c). , can create new thread passing object.memberfunction. don't know how combine both, using memberfunction delegate , passing threadstart function. hints?
i suggest using parallelism built .net.
task.factory.startnew(() => func(c));
Comments
Post a Comment