.net - VC++ Winforms passing member function as argument to BackgroundWorker -


being beginner, struggling syntax here. making generic backgroundworker avoid making separate workers each of many tasks in application. unable figure out how pass member function runworkerasync()

here dowork method's code:

private: system::void backgroundworker2_dowork(system::object^  sender, system::componentmodel::doworkeventargs^  e) {     func<int> ^func = (func<int>^)e->argument;     e->result = func(); } 

let's want bg worker run function named myfunc. want this: runworkerasync(myfunc)

while myfunc member of same class i.e form1

it isn't clear me hangup might be, syntax create func<> isn't different way subscribe dowork event. sample code:

ref class example {     backgroundworker^ worker;     void ondowork(system::object ^sender, system::componentmodel::doworkeventargs ^e) {         auto job = safe_cast<func<int>^>(e->argument);         e->result = job();     }     int myfunc() {         return 42;     } public:     example() : worker(gcnew backgroundworker) {         worker->dowork += gcnew system::componentmodel::doworkeventhandler(this, &example::ondowork);         auto job = gcnew func<int>(this, &example::myfunc);         worker->runworkerasync(job);     } }; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -