c# - Trying to start a thread based on a users choice -
i have combobox many choices. user chooses takes them case statement. in case 1 of items gets choosen string. string want use take start specific function thread. e.g. have function
public void doworkap(){}
and another
public void doworkag(){}
from combo box user makes choice , case statemtn have string called swhichwork , set either "doworkag" or "doworkap"
now in ui code have thread
thread t = null;
and when button pressed function called , in function have
t = new thread(swhichwork); t.start();
this seemed woudl exect swhichwork substituted "doworkag" or "doworkap" instead get
"cannot convert 'string' system.threading.parameterizedthreadstart' "
now take out swhichworks , have following
t = new thread(doworkag); t.start();
this compiles , takes me correct place. question how can have variable string choosen combox case stament take me same place?
if have 2 options, i'd go for
t = new thread(swhichwork == "doworkag" ? doworkag : doworkap);
this work well:
t = new thread(this.gettype().getmethod(swhichwork).invoke(this, new object[]));
Comments
Post a Comment