c# - Invoke method in new thread (method name from string)? -


im trying invoke method on new thread in winforms c# app. need method name come string.

is possible like:

public void newthread(string methodname) {    new thread(new threadstart(methodname)).start(); } 

i've tried cant seem work?

any advice appreciated.

i assuming want call method within class itself.

type classtype = this.gettype(); object obj = activator.createinstance(classtype) object[] parameters = new object[] { _objval }; methodinfo mi = classtype.getmethod("mymethod"); threadstart threadmain = delegate () { mi.invoke(this, parameters); }; new system.threading.thread(threadmain).start(); 

if not replace this class need.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -