Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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#

  • 2 weeks later...
Posted
        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;
           }
       }

  • Administrators
Posted

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;
           }
       }

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...