winforms - .NET keep application alive while waiting for task to complete -


i inherited c# 4.0 winforms app (basically small dashboard) uses producer-consumer pattern. consumer task (literally system.threading.tasks.task) processing data in queue. when user wants shut down app, producer (a tcp socket server) stopped immediately. however, queue may not empty need give user option exit or exit consumer task has finished processing of queued data. if user wants wait consumer task finish, ui naturally needs remain responsive. problem i'm having since code exit application resides in click event handler "exit" button, may need wait consumer task finish while i'm inside click event handler. in nutshell, event handler contains (very ugly) code:

  // loop while there still data in queue   while (queueddata.count > 0)   {     application.doevents(); // ui semi-responsive lot of cpu utilization)   }    // queue empty exit application 

can suggest alternate way of implementing functionality i'm not stuck in tight loop inside of event handler on ui thread? make sense start thread/task @ point handle checking , shut down app thread? much!

you have exit task queued in same queue [by exit button] - when queue finished, exit handler called.

if wanted, update ui 'exit pending...' in meantime.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -