Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CChildFrame in separate thread

CChildFrame in separate thread

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 2 Posters 0 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I have a MDI app, with view based on CHtmlView. Is there any way to launch every CChildFrame in separate thread ? If yes, how can I do that ? I search on internet for this, but I have found nothing ...

    J 1 Reply Last reply
    0
    • _ _Flaviu

      I have a MDI app, with view based on CHtmlView. Is there any way to launch every CChildFrame in separate thread ? If yes, how can I do that ? I search on internet for this, but I have found nothing ...

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      The frames belong to the GUI and should be therefore executed in the GUI (main) thread. I even don't think that it is possible to run the child frames in another thread due to the relationship to the main frame, and the views. Even if it is possible, it would be a nightmare to make it all thread safe. But you can execute specific operations within the child frames or the views in separate threads. A common method is to use worker threads for longer running jobs. Because such threads can not directly access (MFC) UI elements, they have to post (user defined) messages to update UI elements.

      _ 1 Reply Last reply
      0
      • J Jochen Arndt

        The frames belong to the GUI and should be therefore executed in the GUI (main) thread. I even don't think that it is possible to run the child frames in another thread due to the relationship to the main frame, and the views. Even if it is possible, it would be a nightmare to make it all thread safe. But you can execute specific operations within the child frames or the views in separate threads. A common method is to use worker threads for longer running jobs. Because such threads can not directly access (MFC) UI elements, they have to post (user defined) messages to update UI elements.

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        My task is to run some specific html pages, but sending some forms inside these page is taking a little more time, and there is 8-10 html pages ... I was thinking that running every child frame in separate thread would be a good solution ... but I guess is not ... hmm ... I don't know how to shrink the time when these html pages work their tasks ...

        J 1 Reply Last reply
        0
        • _ _Flaviu

          My task is to run some specific html pages, but sending some forms inside these page is taking a little more time, and there is 8-10 html pages ... I was thinking that running every child frame in separate thread would be a good solution ... but I guess is not ... hmm ... I don't know how to shrink the time when these html pages work their tasks ...

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          You can still use threads to do the work and provide some kind of wait indication (cursor, status line, or self closing notification / progress window). The advantage of using threads is that the GUI is not blocked and the user can do other operations meanwhile. But using threads is not making something that requires an amount of time running faster (besides splitting the work and letting multiple threads perform the work in parallel). It just allows doing something else meanwhile.

          _ 1 Reply Last reply
          0
          • J Jochen Arndt

            You can still use threads to do the work and provide some kind of wait indication (cursor, status line, or self closing notification / progress window). The advantage of using threads is that the GUI is not blocked and the user can do other operations meanwhile. But using threads is not making something that requires an amount of time running faster (besides splitting the work and letting multiple threads perform the work in parallel). It just allows doing something else meanwhile.

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            You are perfectly right. Here is the scenario: I should start 8 CHtmlViews, every one of them with a specific web address, and do a login form. Now, every login task, take 3-4 seconds. If a do this for every 8 pages, the time until all 8 pages complete the login is ~30, 35 seconds, but, most important, the main thread, the GUI thread is blocked. That is why I am trying to run every CHtmlView on separate thread, not because the login task is taken less time, but because is not block the main GUI thread ...

            J 1 Reply Last reply
            0
            • _ _Flaviu

              You are perfectly right. Here is the scenario: I should start 8 CHtmlViews, every one of them with a specific web address, and do a login form. Now, every login task, take 3-4 seconds. If a do this for every 8 pages, the time until all 8 pages complete the login is ~30, 35 seconds, but, most important, the main thread, the GUI thread is blocked. That is why I am trying to run every CHtmlView on separate thread, not because the login task is taken less time, but because is not block the main GUI thread ...

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              Put the communication tasks into there own threads and display a place holder in the view meanwhile. Once the communictaion is done, update the view with the data received in the background.

              _ 1 Reply Last reply
              0
              • J Jochen Arndt

                Put the communication tasks into there own threads and display a place holder in the view meanwhile. Once the communictaion is done, update the view with the data received in the background.

                _ Offline
                _ Offline
                _Flaviu
                wrote on last edited by
                #7

                Unfortunately, the communication with the server is done by html page ... :(

                J 1 Reply Last reply
                0
                • _ _Flaviu

                  Unfortunately, the communication with the server is done by html page ... :(

                  J Offline
                  J Offline
                  Jochen Arndt
                  wrote on last edited by
                  #8

                  If have not used CHtmlView so far but I'm quite sure that the networking is done in a separate thread and there are notification messages informing you when a page has been loaded. Anything else would make no sense because a large download would block your GUI. If your GUI is blocked, you are probably waiting somewhere inside a loop instead of handling notifications.

                  _ 1 Reply Last reply
                  0
                  • J Jochen Arndt

                    If have not used CHtmlView so far but I'm quite sure that the networking is done in a separate thread and there are notification messages informing you when a page has been loaded. Anything else would make no sense because a large download would block your GUI. If your GUI is blocked, you are probably waiting somewhere inside a loop instead of handling notifications.

                    _ Offline
                    _ Offline
                    _Flaviu
                    wrote on last edited by
                    #9

                    This is a good news. So, I will launch view after view to do a login to see how is moving my GUI ... if I think well, there is some methods on this CHtmlView which reveal that all tasks inside html gui is made somewhere in backside (I guess):

                    CHtmlView::OnBeforeNavigate2
                    CHtmlView::OnDocumentComplete
                    CHtmlView::OnDownloadBegin
                    CHtmlView::OnDownloadComplete
                    CHtmlView::OnNavigateComplete2
                    CHtmlView::OnNavigateError
                    CHtmlView::OnUpdateUI
                    // ans so on ...

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups