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. Other Discussions
  3. The Weird and The Wonderful
  4. Things that make you go WTF...

Things that make you go WTF...

Scheduled Pinned Locked Moved The Weird and The Wonderful
14 Posts 8 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.
  • G Gary Wheeler

    if (result != Common.ErrorMsg.ErrorNone)
    {
    this.Dispatcher.BeginInvoke((ThreadStart)delegate()
    {
    });
    return;
    }

    I found this in code that is guaranteed to be called on the dispatcher's thread. Sigh2.

    Software Zen: delete this;

    P Offline
    P Offline
    patbob
    wrote on last edited by
    #5

    Given you said it was replicated in multiple places, I can see only one possible perceived value -- to block this function from returning until after the dispatcher thread is finished executing something else. Such behavior isn't guaranteed, but it would work just often enough that I can easily see someone clueless thinking it does. Before totally writing it off, I'd look carefully at what's done with the dispatcher prior to executing this code. As pointed out, this only makes sense if its run with an Invoke, instead of the BeginInvoke that's being used. Nevermind :(

    We can program with only 1's, but if all you've got are zeros, you've got nothing.

    G 1 Reply Last reply
    0
    • P patbob

      Given you said it was replicated in multiple places, I can see only one possible perceived value -- to block this function from returning until after the dispatcher thread is finished executing something else. Such behavior isn't guaranteed, but it would work just often enough that I can easily see someone clueless thinking it does. Before totally writing it off, I'd look carefully at what's done with the dispatcher prior to executing this code. As pointed out, this only makes sense if its run with an Invoke, instead of the BeginInvoke that's being used. Nevermind :(

      We can program with only 1's, but if all you've got are zeros, you've got nothing.

      G Offline
      G Offline
      Gary Wheeler
      wrote on last edited by
      #6

      It's a BeginInvoke call, which only blocks (very) briefly while the work item is queued to the dispatcher. The dispatcher in turn will execute a brief delay at some point executing the 'empty' work item.

      Software Zen: delete this;

      P 1 Reply Last reply
      0
      • G Gary Wheeler

        if (result != Common.ErrorMsg.ErrorNone)
        {
        this.Dispatcher.BeginInvoke((ThreadStart)delegate()
        {
        });
        return;
        }

        I found this in code that is guaranteed to be called on the dispatcher's thread. Sigh2.

        Software Zen: delete this;

        R Offline
        R Offline
        RafagaX
        wrote on last edited by
        #7

        Aaaahhh!, nothing like a do nothing instruction early in the morning... :)

        CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

        1 Reply Last reply
        0
        • G Gary Wheeler

          That explains why he copy/pasted it all over the place.

          Software Zen: delete this;

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #8

          Procedural Object Oriented Programming (POOP).

          I was brought up to respect my elders. I don't respect many people nowadays.
          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          G 1 Reply Last reply
          0
          • P Pete OHanlon

            Procedural Object Oriented Programming (POOP).

            I was brought up to respect my elders. I don't respect many people nowadays.
            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            G Offline
            G Offline
            Gary Wheeler
            wrote on last edited by
            #9

            Another guy here has his Special High-Interest Task list.

            Software Zen: delete this;

            1 Reply Last reply
            0
            • G Gary Wheeler

              It's a BeginInvoke call, which only blocks (very) briefly while the work item is queued to the dispatcher. The dispatcher in turn will execute a brief delay at some point executing the 'empty' work item.

              Software Zen: delete this;

              P Offline
              P Offline
              patbob
              wrote on last edited by
              #10

              D'Oh! I wasn't paying attention and thought it was an Invoke call. Yeah, BeginInvoke has absolutely no value :)

              We can program with only 1's, but if all you've got are zeros, you've got nothing.

              1 Reply Last reply
              0
              • G Gary Wheeler

                if (result != Common.ErrorMsg.ErrorNone)
                {
                this.Dispatcher.BeginInvoke((ThreadStart)delegate()
                {
                });
                return;
                }

                I found this in code that is guaranteed to be called on the dispatcher's thread. Sigh2.

                Software Zen: delete this;

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #11

                I forget exactly what the purpose was, but I've seen something very similar done in WPF. The purpose was something like forcing the rendering to refresh. Though, I thought some "priority" (or something like that) was necessary for it to work. I know, vague, but there could be a real purpose (that they apparently didn't leave a comment for).

                Thou mewling ill-breeding pignut!

                G 1 Reply Last reply
                0
                • A AspDotNetDev

                  I forget exactly what the purpose was, but I've seen something very similar done in WPF. The purpose was something like forcing the rendering to refresh. Though, I thought some "priority" (or something like that) was necessary for it to work. I know, vague, but there could be a real purpose (that they apparently didn't leave a comment for).

                  Thou mewling ill-breeding pignut!

                  G Offline
                  G Offline
                  Gary Wheeler
                  wrote on last edited by
                  #12

                  WPF has the same constraint that you had under Win32 and MFC: you can only modify UI objects from the UI thread. I think the intent here was to promoted a UI change to the UI thread. Unfortunately, this code appeared in handlers that are already guaranteed to be called from the UI thread.

                  Software Zen: delete this;

                  1 Reply Last reply
                  0
                  • G Gary Wheeler

                    if (result != Common.ErrorMsg.ErrorNone)
                    {
                    this.Dispatcher.BeginInvoke((ThreadStart)delegate()
                    {
                    });
                    return;
                    }

                    I found this in code that is guaranteed to be called on the dispatcher's thread. Sigh2.

                    Software Zen: delete this;

                    B Offline
                    B Offline
                    BobJanova
                    wrote on last edited by
                    #13

                    That's a pretty special no-op. As for using Invoke/BeginInvoke though, unless it's really really obvious that it can only be called in the dispatch thread (e.g. it's in an event handler or something), perhaps it used to be used from multiple threads, or the author couldn't be sure?

                    G 1 Reply Last reply
                    0
                    • B BobJanova

                      That's a pretty special no-op. As for using Invoke/BeginInvoke though, unless it's really really obvious that it can only be called in the dispatch thread (e.g. it's in an event handler or something), perhaps it used to be used from multiple threads, or the author couldn't be sure?

                      G Offline
                      G Offline
                      Gary Wheeler
                      wrote on last edited by
                      #14

                      BobJanova wrote:

                      it can only be called in the dispatch thread (e.g. it's in an event handler

                      Got it in one. I explained this fact to the guy a number of times, and it still didn't seem to sink in.

                      Software Zen: delete this;

                      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