DragDrop file to textbox locks windows explorer

gardet

Newcomer
Joined
Aug 24, 2009
Messages
10
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#
 
Code:
        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;
            }
        }
 
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.

Code:
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;
            }
        }
 
Worked like a charm, on both problems, no locking the explorer window and no locking the form, thank you so much.
 
Back
Top