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. .NET (Core and Framework)
  4. Post message to event queue [modified]

Post message to event queue [modified]

Scheduled Pinned Locked Moved .NET (Core and Framework)
questiondesignalgorithmsdata-structures
6 Posts 3 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.
  • P Offline
    P Offline
    progDes
    wrote on last edited by
    #1

    Hi, Here is a situation. I need to perform long operation in UI thread. I must do it in UI thread, cause algorithm uses 3rdparty resources managed by UI thread. And these resources are not thread safe. So, I do it in UI thread. Because operation is very long I would like to not block the application. What I want is: 1) Interrupt algorithm execution. Store some message in message queue that algorithm must be resolved. 2) Application process all pending events in the queue (key eents, mouse events, draw events etc). 3) I get the the control again in some my handler. (All in the same thread) Similar to what I would do with PostMessage. Like a System::Windows::Forms::Timer with 0 interval (which is not allowed). How can I do that? And here is another detail: I'm doing all this NOT from UI control class. In fact I do it in static member function. But I'm in main(UI) thread. Thanks. /////////////////////////////////////////////////////////////////////////////// Found a resolution. System::Windows::Threading::Dispatcher class does exactly what I need. And it doesnt require a UI control (like COntrol::BeginInvoke). Works perfect. Theme closed.

    modified on Wednesday, February 23, 2011 8:47 AM

    P R 2 Replies Last reply
    0
    • P progDes

      Hi, Here is a situation. I need to perform long operation in UI thread. I must do it in UI thread, cause algorithm uses 3rdparty resources managed by UI thread. And these resources are not thread safe. So, I do it in UI thread. Because operation is very long I would like to not block the application. What I want is: 1) Interrupt algorithm execution. Store some message in message queue that algorithm must be resolved. 2) Application process all pending events in the queue (key eents, mouse events, draw events etc). 3) I get the the control again in some my handler. (All in the same thread) Similar to what I would do with PostMessage. Like a System::Windows::Forms::Timer with 0 interval (which is not allowed). How can I do that? And here is another detail: I'm doing all this NOT from UI control class. In fact I do it in static member function. But I'm in main(UI) thread. Thanks. /////////////////////////////////////////////////////////////////////////////// Found a resolution. System::Windows::Threading::Dispatcher class does exactly what I need. And it doesnt require a UI control (like COntrol::BeginInvoke). Works perfect. Theme closed.

      modified on Wednesday, February 23, 2011 8:47 AM

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      progDes wrote:

      I must do it in UI thread, cause algorithm uses 3rdparty resources managed by UI thread. And these resources are not thread safe. So, I do it in UI thread

      There may be a way, but apparently there's no will. More information would be helpful.

      1 Reply Last reply
      0
      • P progDes

        Hi, Here is a situation. I need to perform long operation in UI thread. I must do it in UI thread, cause algorithm uses 3rdparty resources managed by UI thread. And these resources are not thread safe. So, I do it in UI thread. Because operation is very long I would like to not block the application. What I want is: 1) Interrupt algorithm execution. Store some message in message queue that algorithm must be resolved. 2) Application process all pending events in the queue (key eents, mouse events, draw events etc). 3) I get the the control again in some my handler. (All in the same thread) Similar to what I would do with PostMessage. Like a System::Windows::Forms::Timer with 0 interval (which is not allowed). How can I do that? And here is another detail: I'm doing all this NOT from UI control class. In fact I do it in static member function. But I'm in main(UI) thread. Thanks. /////////////////////////////////////////////////////////////////////////////// Found a resolution. System::Windows::Threading::Dispatcher class does exactly what I need. And it doesnt require a UI control (like COntrol::BeginInvoke). Works perfect. Theme closed.

        modified on Wednesday, February 23, 2011 8:47 AM

        R Offline
        R Offline
        RobCroll
        wrote on last edited by
        #3

        Could you open a new non-visible window and do it there?

        "You get that on the big jobs."

        P 1 Reply Last reply
        0
        • R RobCroll

          Could you open a new non-visible window and do it there?

          "You get that on the big jobs."

          P Offline
          P Offline
          progDes
          wrote on last edited by
          #4

          If this window will be in the same thread as main UI thread (which is requirement) - it will block application anyway.

          R 1 Reply Last reply
          0
          • P progDes

            If this window will be in the same thread as main UI thread (which is requirement) - it will block application anyway.

            R Offline
            R Offline
            RobCroll
            wrote on last edited by
            #5

            Ok, I didn't realise it had to be in the main UI thread. If you can host the 3rd party resources in a separate UI thread, you may find an answer here

            "You get that on the big jobs."

            P 1 Reply Last reply
            0
            • R RobCroll

              Ok, I didn't realise it had to be in the main UI thread. If you can host the 3rd party resources in a separate UI thread, you may find an answer here

              "You get that on the big jobs."

              P Offline
              P Offline
              progDes
              wrote on last edited by
              #6

              No I cant. Found a resolution. System::Windows::Threading::Dispatcher class does exactly what I need. And it doesnt require a UI control (like COntrol::BeginInvoke). Woeks perfect.

              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