Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. About multithreaded call CopyFileEx copy large files (more than 1GB) when the phenomenon of suspended animation
Forum Updated to NodeBB v4.3 + New Features

About multithreaded call CopyFileEx copy large files (more than 1GB) when the phenomenon of suspended animation

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 5 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jsulmJ jsulm

    @lwei2 said in About multithreaded call CopyFileEx copy large files (more than 1GB) when the phenomenon of suspended animation:

    Because the child thread is running on the main thread

    This makes no sense! A child thread cannot run on main thread. Threads are independent from each other. I'm already quite confused from what you're writing...

    L Offline
    L Offline
    lwei2
    wrote on last edited by
    #21

    @jsulm I didn't say that the child thread cannot run on the main thread.What I want to say is that the main thread is stalled because the child thread is waiting for the return value of CopyFileEx without running the code behind CopyFileEx.Such as:

    void run()
    {
        const wchar_t *src = reinterpret_cast<const wchar_t *>(srcPath.utf16());
        const wchar_t *dst = reinterpret_cast<const wchar_t *>(dstPath.utf16());
        m_nCopyValue = 0;
        emit sigCopyValue(0, m_nCopyValue);
        qWarning()<<"m_nCopyValue="<<m_nCopyValue;
        BOOL m_bCancel = FALSE;
        qWarning()<<"startTime="<<QTime::currentTime().toString("hh:mm:ss");
        CopyFileEx((LPCWSTR)src,(LPCWSTR)dst, CallBackCopyProgressFunc, this, (LPBOOL)m_bCancel, COPY_FILE_FAIL_IF_EXISTS);  //wait 30 to 60 seconds before executing the following code
    
    //there is other code here
    
    }
    
    JonBJ 1 Reply Last reply
    0
    • L lwei2

      @jsulm I didn't say that the child thread cannot run on the main thread.What I want to say is that the main thread is stalled because the child thread is waiting for the return value of CopyFileEx without running the code behind CopyFileEx.Such as:

      void run()
      {
          const wchar_t *src = reinterpret_cast<const wchar_t *>(srcPath.utf16());
          const wchar_t *dst = reinterpret_cast<const wchar_t *>(dstPath.utf16());
          m_nCopyValue = 0;
          emit sigCopyValue(0, m_nCopyValue);
          qWarning()<<"m_nCopyValue="<<m_nCopyValue;
          BOOL m_bCancel = FALSE;
          qWarning()<<"startTime="<<QTime::currentTime().toString("hh:mm:ss");
          CopyFileEx((LPCWSTR)src,(LPCWSTR)dst, CallBackCopyProgressFunc, this, (LPBOOL)m_bCancel, COPY_FILE_FAIL_IF_EXISTS);  //wait 30 to 60 seconds before executing the following code
      
      //there is other code here
      
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #22

      @lwei2 said in About multithreaded call CopyFileEx copy large files (more than 1GB) when the phenomenon of suspended animation:

      the main thread is stalled because the child thread is waiting for the return value of CopyFileEx

      Your main thread cannot afford to wait on the child thread! If the child runs CopyFileEx it's going not going to exit until that has had its extra 30 seconds at the end, which is the whole point of what you are wanting to avoid.

      That's why if it waits at all the main thread should only wait until the child signals the 100% completion.

      If you are using the wait on the child thread for some other purpose, then you will need a third thread for the CopyFileEx. Whatever, the only way you will be able to avoid waiting for the CopyFileEx's extra 30 seconds is if the CopyFileEx runs in its own thread, and sends a signal when the 100% is reached.

      L 1 Reply Last reply
      0
      • L lwei2

        @jsulm I'm just showing the progress value on the main thread. I didn't wait, the child thread itself waited 30 to 60 seconds while calling CopyFIleEx before continuing with the rest of the code. Because the child thread is running on the main thread, if the child thread is waiting without sending a signal to the main thread, the main thread will also be stuck.

        JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #23

        @lwei2 It is flushing time. Therefore, progress display is sort of a lie. But on Windows you may try some MS code for file copy and do not use Qt file copy. I recently coded file copy on Linux with Qt and can not do anything about flushing.
        If the file size is too big, chop the file into small pieces and copy them one after another since you may need cancel feature. The optimal size is 131072.

        1 Reply Last reply
        0
        • JonBJ JonB

          @lwei2 said in About multithreaded call CopyFileEx copy large files (more than 1GB) when the phenomenon of suspended animation:

          the main thread is stalled because the child thread is waiting for the return value of CopyFileEx

          Your main thread cannot afford to wait on the child thread! If the child runs CopyFileEx it's going not going to exit until that has had its extra 30 seconds at the end, which is the whole point of what you are wanting to avoid.

          That's why if it waits at all the main thread should only wait until the child signals the 100% completion.

          If you are using the wait on the child thread for some other purpose, then you will need a third thread for the CopyFileEx. Whatever, the only way you will be able to avoid waiting for the CopyFileEx's extra 30 seconds is if the CopyFileEx runs in its own thread, and sends a signal when the 100% is reached.

          L Offline
          L Offline
          lwei2
          wrote on last edited by
          #24

          @JonB Could you please tell me how I can wait for it to copy to 100% before sending the signal?

          JonBJ 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #25

            Hi,

            Did you consider using the COPY_FILE_NO_BUFFERING flag as recommended in the documentation for large files ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            L 1 Reply Last reply
            1
            • L lwei2

              @JonB Could you please tell me how I can wait for it to copy to 100% before sending the signal?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #26

              @lwei2 said in About multithreaded call CopyFileEx copy large files (more than 1GB) when the phenomenon of suspended animation:

              @JonB Could you please tell me how I can wait for it to copy to 100% before sending the signal?

              I really don't understand. You said that presently CopyFileEx does not return till after the extra 30 seconds of "flushing" at the end, so if that is what you mean don't send the signal till CopyFileEx is done, which is what you have now. If you mean when the progress reaches 100%, before the extra 30 seconds, then you detect that in your CallBackCopyProgressFunc, and send the signal from there. This latter approach will require the CopyFileEx be run in its own thread.

              In any case, first try @SGaist excellent spot of COPY_FILE_NO_BUFFERING flag, it might change the behaviour over to what you want by eliminating a large "flush" at the end.

              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                Did you consider using the COPY_FILE_NO_BUFFERING flag as recommended in the documentation for large files ?

                L Offline
                L Offline
                lwei2
                wrote on last edited by
                #27

                @SGaist I tried to use COPY_FILE_NO_BUFFERING, but I had the same problem.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved