Anonamous delegates gone mad!
-
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[^])
-
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[^])
Yeah, that looks like abuse.
-
Yeah, that looks like abuse.
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.
-
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[^])
-
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 nowI'd question perhaps how maintainable that is though!
-
I'd question perhaps how maintainable that is though!
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 -
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 nowleppie 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.
-
I'd question perhaps how maintainable that is though!
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:
-
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:
Yes, I suppose.