gardet Posted September 26, 2009 Posted September 26, 2009 As the title says, i have this textbox where i drop a file, and then i have like 6 external applications that works with the file, they get started with process(). The whole process takes about 20 minutes, and during that time the window i draged the file from gets locked. It gets "unlocked" again when the DragDrop-function is done, is there a way to "unlock" the window instead of having it locked until its finished? I also have this side question, when the process() is running my form is also getting "locked", any way to prevent that? -- Henrik using C# Quote
Administrators PlausiblyDamp Posted September 26, 2009 Administrators Posted September 26, 2009 Any chance you could post the code you are using, makes it easier to diagnose problems when there is some code to look at. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
gardet Posted October 7, 2009 Author Posted October 7, 2009 private void file_DragDrop(object sender, DragEventArgs e) { string[] file_path = (string[])e.Data.GetData(DataFormats.FileDrop, false); string file = file_path[0]; Process pr = new Process(); pr.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; pr.StartInfo.CreateNoWindow = true; pr.StartInfo.FileName = Directory.GetCurrentDirectory() + "\\Rar.exe"; pr.StartInfo.Arguments = "a -m0 -vn -ep \"" + file + "\""; pr.Start(); while (pr.HasExited == false) { Thread.Sleep(1000); } pr.Close(); } private void file_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Copy; } } Quote
Administrators PlausiblyDamp Posted October 8, 2009 Administrators Posted October 8, 2009 The problem is your code is performing all it's work an the main thread and this thread is blocking explorer. Probably the easiest fix is to use a delegate and invoke this on a background thread. The following should give you an idea. private void file_DragDrop(object sender, DragEventArgs e) { string[] file_path = (string[])e.Data.GetData(DataFormats.FileDrop, false); string file = file_path[0]; ProcessFileDelegate proc = ProcessFile; proc.BeginInvoke(file,null,null); } private static void ProcessFile(string file) { Process pr = new Process(); pr.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; pr.StartInfo.CreateNoWindow = true; pr.StartInfo.FileName = Directory.GetCurrentDirectory() + "\\Rar.exe"; pr.StartInfo.Arguments = "a -m0 -vn -ep \"" + file + "\""; pr.Start(); while (pr.HasExited == false) { Thread.Sleep(1000); } pr.Close(); } private void file_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Copy; } } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
gardet Posted October 9, 2009 Author Posted October 9, 2009 Worked like a charm, on both problems, no locking the explorer window and no locking the form, thank you so much. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.