c# - How can I update a UI progressbar or backgroundworker from code in a separate class? -


somewhat new c# have major problem getting these things work because if background worker running long process using method class, class has no access background worker in order update progress.

for instance:

private void bgworker_dowork(object sender doworkeventargs e) {     bgargs args = e.argument bgargs;     myclass objmyclass = new myclass();      myclass.mymethod(strvalue, args.option);      //do based on return value of long process. } 

if try update bgworker class "myclass", cannot "see" bgworker, doesn't exist in context of class, it's in ui class because in visual studio, that's drag toolbox.

the way i've gotten work pass whole ui form class, creates other problems when trying access class anywhere main form. there update progress bar manually via progressbar1.performstep() runs through loops.

also, i've changed modifier on progress bar internal, it's not class doesn't see progress bar.

i might able pass bgworker class through method, doesn't seem right.

i think architecture needs revising here. background worker running operations in background, out-of-sight-out-of-mind. while running, can accept feedback observing backgroundworker.progresschanged event, increment progress bar performstep(). however, shouldn't attempt alter backgroundworker while running. gets threading issues, i'm not sure want :) see, backgroundworker uses different thread perform operations when runs, changing while running means have access thread performing work upon. gets ugly. best give method execute, let run, check in on progresschanged, , wait finish.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -