c# - task deadlock when invoking in worker threads -
i have windows form program (**vs 2010 .net 4 **) detecting recursively folders , sub folders of directory , optimizing files. tasking library , have progressbar shows progress of item , label near progressbar shows current file. have settext(string text) method , delegate (delegate void settextcallback(string text);) use purpose. when want show messagebox @ end of process think deadlock. when don't use task.wait(); in button6_click goes ok , ui won't hang. code: public partial class form1 : form { int maxfilecounter = 0; static int filecounter = 0; delegate void settextcallback(string text); delegate void setprogresscallback(int i); private void button6_click(object sender, eventargs e) { task task = task.factory.startnew(() => { editfiles(txtfilepath.text); }); task.wait(); messagebox.show("finished"); } private void editfiles(string directorypath) { try { //directoryinfo dirinfo = new directo...