c# - Best pattern for "Do some work and quit" -
i'm writing little gui program work , exits afterwards. while work done, gui thread updated infos user.
this pattern i'm using , i'm thinking it's not elegant one:
static void mainform_loaded(beoexport exporter) { // thread 1 runs export workerthread = new thread(() => { exporter.startexport(); // don't exit immediately, user sees someting if work done fast thread.sleep(1000); }); // thread 2 waits thread 1 , exits program afterwards waiterthread = new thread(() => { workerthread.join(); application.exit(); }); workerthread.start(); waiterthread.start(); }
so pattern/mechanics use same?
to clarify: not interested in way update gui thread. that's done. might sound esoteric lookig right way quit application.
if could, give dave credits, since pointed out usefulness of backgroundworker.
have considered backgroundworker
thread instead? can use reportprogress
method , progresschanged
event update gui (with progress bar perhaps), assuming can refactor beoexport.startexport
method report progress. gives users visible feedback work happening.
Comments
Post a Comment