Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7441193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:58:19+00:00 2026-05-29T10:58:19+00:00

how do i let UIthread to execute a command when im in some thread

  • 0

how do i let UIthread to execute a command when im in some thread
the code below is called by a thread but the line i want to run in UIthread .. doesn’t work if i called it like that ..
the form lag a little and the process fan got fast like it’s in infinity loop.. then it gives me an error “stackoverflowexception”

my application is a file manager .. (copy, cut, paste, new folder..etc) .. and dirRecursive(string path) .. shows me the files and folders in a listView with its icons so every time i do something like (new folder or paste) i have to call dirRecursive to update the listView

note:

  • it works excellent before i tried to execute PasteFromCopy with a thread ..
  • it works excellent when i remove the dirRecursive(..) line from the paste method .. but i need to update listview automatically after the paste is done .. that why i have to call it from PasteFromCopy but using UIThread
  • if i used UIThread to PASTE then the form will lag when a file is being copyied .. you know

    please help 🙂 thanks in advance

    private void PasteFromCopy(object dest)
        {
            foreach (ListViewItem item in copiedItems)
            {
                string _dest = (string)dest;
                string itemName = item.Text;
                string itemPath = item.ToolTipText;
                string itemDest = Path.Combine(_dest, itemName);
                if (IsFolder(itemPath))
                {
                    if (Directory.Exists(itemDest))
                    {
                        if (MessageBox.Show(itemName + " is already exists .. Do you want to overwrite it and its all contents?"
                            , "Overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
                        {
                            CopyDirectory(itemPath, itemDest, true);
                        }
                    }
                    else
                        CopyDirectory(itemPath, itemDest, false);
                }
                else
                {
                    if (File.Exists(itemDest))
                    {
                        if (MessageBox.Show(itemName + " is already exists .. Do you want to overwrite it?"
                        , "Overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
                        {
                            InfoLabel("Copying " + itemName + " ...");
                            File.Copy(itemPath, itemDest, true);
                        }
                    }
                    else
                    {
                        InfoLabel("Copying " + itemName + " ...");
                        File.Copy(itemPath, itemDest, false);
                    }
                }
                InfoLabel("Paste done.");
    
                dirRecursive(currAddress);   // here is line i need to execute from UIthread
            }
        }
    
    • 1 1 Answer
    • 0 Views
    • 0 Followers
    • 0
    Share
    • Facebook
    • Report

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    1 Answer

    • Voted
    • Oldest
    • Recent
    • Random
    1. Editorial Team
      Editorial Team
      2026-05-29T10:58:19+00:00Added an answer on May 29, 2026 at 10:58 am

      try replacing this line

      dirRecursive(currAddress);
      

      with

      if (InvokeRequired)
      {
          Action a = ()=>dirRecursive(currAddress);
          Invoke(a);
      }
      

      This is assuming you’re using WinForms and not WPF, you haven’t specified. Also ‘InvokeRequired’ and ‘Invoke’ are both members of a System.Windows.Forms.Control so your PasteFromCopy would need to be a method on your form.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
        • Report

    Sidebar

    Related Questions

    I've stress tested the code below and it seems to work fine - what
    Let's say i have this block of code, <div id=id1> This is some text
    Let me post some code before I ask question. public Object returnSomeResult() { Object
    Let's say you have a class called Customer, which contains the following fields: UserName
    Let's say I have a drive such as C:\ , and I want to
    Let's consider the following 3 code lines: struct stat buffer; status = lstat(file.c_str(), &buffer);
    Let's say i go to myblog.com/post/12 . The /post handler is already defined, but
    Let's say I have saved this kind of data (some text '.date(d).' some text)
    Let's say I have some content classes like Page, TabGroup, Tab, etc. Certain of
    Let's create WinForms Application (I have Visual Studio 2008 running on Windows Vista, but

    Explore

    • Home
    • Add group
    • Groups page
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges
    • Users
    • Help
    • SEARCH

    Footer

    © 2021 The Archive Base. All Rights Reserved
    With Love by The Archive Base

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.