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. Anonamous delegates gone mad!

Anonamous delegates gone mad!

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpwpfcom
9 Posts 4 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.
  • D Offline
    D Offline
    Derek Bartram
    wrote on last edited by
    #1

    Thread t = new Thread(delegate()
    {
    while (keepShowing)
    {
    this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new RefreshDelegate(delegate()
    {
    if (!(Mouse.LeftButton == MouseButtonState.Released &&
    Mouse.MiddleButton == MouseButtonState.Released &&
    Mouse.RightButton == MouseButtonState.Released &&
    Mouse.XButton1 == MouseButtonState.Released &&
    Mouse.XButton2 == MouseButtonState.Released))
    {
    if (!insideControl)
    {
    for (int i = 0; i < this.MenuButtons.Count; i++)
    {
    if (this.MenuButtons[i].PopupMenu != null && this.MenuButtons[i].PopupMenu.IsMouseInside)
    {
    return;
    }
    }
    keepShowing = false;
    }
    }
    }));
    Thread.Sleep(10);
    }

                this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new RefreshDelegate(delegate()
                {
                    this.IsOpen = false;
                }));
            });
            t.Name = "Capture Click Events Thread";
            t.Priority = ThreadPriority.AboveNormal;
            t.Start();
    

    A thread with anonamous delegate to a dispatcher with an anonamous delegate.... crazy talk I say. I don't remember exactly where it is (hence I havn't posted it), but I have a thread with anonamous delegate to a dispatcher with an anonamous delegate to a thread with anonamous delegate to a dispatcher with an anonamous delegate somewhere. *Ps. It's in the RibbonControl library, oops (http://www.codeproject.com/KB/WPF/ribboncontrol.aspx[^])

    P L 2 Replies Last reply
    0
    • D Derek Bartram

      Thread t = new Thread(delegate()
      {
      while (keepShowing)
      {
      this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new RefreshDelegate(delegate()
      {
      if (!(Mouse.LeftButton == MouseButtonState.Released &&
      Mouse.MiddleButton == MouseButtonState.Released &&
      Mouse.RightButton == MouseButtonState.Released &&
      Mouse.XButton1 == MouseButtonState.Released &&
      Mouse.XButton2 == MouseButtonState.Released))
      {
      if (!insideControl)
      {
      for (int i = 0; i < this.MenuButtons.Count; i++)
      {
      if (this.MenuButtons[i].PopupMenu != null && this.MenuButtons[i].PopupMenu.IsMouseInside)
      {
      return;
      }
      }
      keepShowing = false;
      }
      }
      }));
      Thread.Sleep(10);
      }

                  this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new RefreshDelegate(delegate()
                  {
                      this.IsOpen = false;
                  }));
              });
              t.Name = "Capture Click Events Thread";
              t.Priority = ThreadPriority.AboveNormal;
              t.Start();
      

      A thread with anonamous delegate to a dispatcher with an anonamous delegate.... crazy talk I say. I don't remember exactly where it is (hence I havn't posted it), but I have a thread with anonamous delegate to a dispatcher with an anonamous delegate to a thread with anonamous delegate to a dispatcher with an anonamous delegate somewhere. *Ps. It's in the RibbonControl library, oops (http://www.codeproject.com/KB/WPF/ribboncontrol.aspx[^])

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

      Yeah, that looks like abuse.

      D 1 Reply Last reply
      0
      • P PIEBALDconsult

        Yeah, that looks like abuse.

        D Offline
        D Offline
        Derek Bartram
        wrote on last edited by
        #3

        It's the way forward ;P Still, it's a shame they didn't go back to the ways of .NET 1 where you could just directly modify gui properties directly. I remember seeing the justification for it, but frankly .NET 1 never gave me any problems so why change it.

        1 Reply Last reply
        0
        • D Derek Bartram

          Thread t = new Thread(delegate()
          {
          while (keepShowing)
          {
          this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new RefreshDelegate(delegate()
          {
          if (!(Mouse.LeftButton == MouseButtonState.Released &&
          Mouse.MiddleButton == MouseButtonState.Released &&
          Mouse.RightButton == MouseButtonState.Released &&
          Mouse.XButton1 == MouseButtonState.Released &&
          Mouse.XButton2 == MouseButtonState.Released))
          {
          if (!insideControl)
          {
          for (int i = 0; i < this.MenuButtons.Count; i++)
          {
          if (this.MenuButtons[i].PopupMenu != null && this.MenuButtons[i].PopupMenu.IsMouseInside)
          {
          return;
          }
          }
          keepShowing = false;
          }
          }
          }));
          Thread.Sleep(10);
          }

                      this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new RefreshDelegate(delegate()
                      {
                          this.IsOpen = false;
                      }));
                  });
                  t.Name = "Capture Click Events Thread";
                  t.Priority = ThreadPriority.AboveNormal;
                  t.Start();
          

          A thread with anonamous delegate to a dispatcher with an anonamous delegate.... crazy talk I say. I don't remember exactly where it is (hence I havn't posted it), but I have a thread with anonamous delegate to a dispatcher with an anonamous delegate to a thread with anonamous delegate to a dispatcher with an anonamous delegate somewhere. *Ps. It's in the RibbonControl library, oops (http://www.codeproject.com/KB/WPF/ribboncontrol.aspx[^])

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          Nothing really wrong with that... maybe you are just scared of nested closures ;P You should probably stay away from any functional language in that case :)

          xacc.ide - now with IronScheme support
          IronScheme - 1.0 alpha 2 out now

          D 1 Reply Last reply
          0
          • L leppie

            Nothing really wrong with that... maybe you are just scared of nested closures ;P You should probably stay away from any functional language in that case :)

            xacc.ide - now with IronScheme support
            IronScheme - 1.0 alpha 2 out now

            D Offline
            D Offline
            Derek Bartram
            wrote on last edited by
            #5

            I'd question perhaps how maintainable that is though!

            L M 2 Replies Last reply
            0
            • D Derek Bartram

              I'd question perhaps how maintainable that is though!

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              I don't even know the code that belongs to and it is rather easy to see what it does. It needs a delegate to invoke back to the GUI thread from within the runner thread. As an exercise, convert that code to a non-anonymous delegate way, you will see the resulting code will be much more disconnected, and a lot more verbose. Unless he is repeating the code anywhere else, I see no reason to refactor it.

              xacc.ide - now with IronScheme support
              IronScheme - 1.0 alpha 2 out now

              D 1 Reply Last reply
              0
              • L leppie

                I don't even know the code that belongs to and it is rather easy to see what it does. It needs a delegate to invoke back to the GUI thread from within the runner thread. As an exercise, convert that code to a non-anonymous delegate way, you will see the resulting code will be much more disconnected, and a lot more verbose. Unless he is repeating the code anywhere else, I see no reason to refactor it.

                xacc.ide - now with IronScheme support
                IronScheme - 1.0 alpha 2 out now

                D Offline
                D Offline
                Derek Bartram
                wrote on last edited by
                #7

                leppie wrote:

                you will see the resulting code will be much more disconnected

                Certainly, however convert it to the .NET 1.0 way and it'll be far less confusing.

                1 Reply Last reply
                0
                • D Derek Bartram

                  I'd question perhaps how maintainable that is though!

                  M Offline
                  M Offline
                  MidwestLimey
                  wrote on last edited by
                  #8

                  Derek Bartram wrote:

                  I'd question perhaps how maintainable that is though!

                  The more I think about it, the more I find the answer is very. All the code is in one place, and isn't abomnably long. At worst it could be said that the threaded method should be declared rather anonymous, the others are just what anonymous methods were intended for.


                  I'm largely language agnostic


                  After a while they all bug me :doh:


                  D 1 Reply Last reply
                  0
                  • M MidwestLimey

                    Derek Bartram wrote:

                    I'd question perhaps how maintainable that is though!

                    The more I think about it, the more I find the answer is very. All the code is in one place, and isn't abomnably long. At worst it could be said that the threaded method should be declared rather anonymous, the others are just what anonymous methods were intended for.


                    I'm largely language agnostic


                    After a while they all bug me :doh:


                    D Offline
                    D Offline
                    Derek Bartram
                    wrote on last edited by
                    #9

                    Yes, I suppose.

                    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