Use WPF Dispatcher to invoke event handler only when needed

By Robert Ellison. Updated on Saturday, September 29, 2018.

Use WPF Dispatcher to invoke event handler only when needed

After floundering a bit with the WPF Dispatcher I've come up with a simple way to make sure an event handler executes on the UI thread without paying the overhead of always invoking a delegate.

This has the benefit (for me at least) of being very easy to remember. Hook up the event handler and then if there's a chance it could be called from a different thread wrap it using the pattern above. It's easier to read than an anonymous delegate and much faster than defining a specific delegate for the event in question.

I haven't tested the various methods to see which is the fastest yet… will get round to this at some point.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Use WPF Dispatcher to invoke event handler only when needed #code #wpf #tips How to Invoke or BeginInvoke an event handler to the UI thread using the WPF Dispatcher. )

Top 5 reasons to hate the Facebook like button

By Robert Ellison. Updated on Thursday, November 12, 2015.

5. Validation

The metadata required to use the like button looks like this:

[code:html]





[/code]

But the property attribute isn't valid html or xhtml. The “Open” Graph Protocol says that it's inspired by Dublin Core. DC manages to get by using the name attribute like any other meta tag - why can't Open Graph? It's not the worst problem but it just seems needlessly irksome. Facebook has published a presentation describing their design decisions. This would be great, but it's in that Lessig one word per slide style and so it's attractive but completely useless without the presenter.

4. Fragility

Facebook's documentation is frustratingly sparse. For example you need to specify the owner of the page using a Facebook ID, and once you've chosen a name for your profile this is hard to find. The information vacuum has been filled with many erroneous blog posts saying to use the name, or some number from a shared photo (the best source is http://graph.facebook.com/robert.ellison, substituting your own username). Once you've got the admin ID wrong, you can't correct it - the first admin specified is fixed forever. What happens if a site is hacked and a bad actor sets themselves up as the admin? Surely something like the Google Webmaster Tools authentication scheme could have been used instead?

3. Pages with more than one object

Describing the object being liked in the head element limits you to one object per page. For some sites this is perfect, but what about a blog where you have many posts on the home page? It would be useful to have a like button per post, pointing at the permalink for the post in question. I've worked around this by having a like button for the blog on the home page, and a like button for each post on the post pages. Not ideal. I'm using the iframe version of the gadget, possibly there's some more flexibility with the XBML variant.

2. Duplicating existing pages

Let's say you've spent the past couple of years building up a Facebook page for your site/band/blog/movie and have thousands of fans. When you click your new like button for the first time you create a whole new page. There's no way to tell the like button about the existing page or the existing page about the like button. You now have at least two pages to worry about managing and potentially many, many more. You're also starting from scratch on the ‘like’ count, so even if your brand is already popular on Facebook it's back to Billy no-mates for you.

I can't believe this won't be fixed at some point. As with admin authentication above there must be a better way to establish ownership of various objects in the social graph.

1. Vocabulary

Doctors defend genital nick for girls

For better or worse Facebook has the inexorable pull to start making the semantic web a reality. Given this, and that there are something like twenty-four thousand verbs in the English language it's time for more expressiveness than ‘like’. You also can't comment on the ‘liked’ item in your stream (yet) so no clarification or discussion is possible.

--

Having said all that, if you enjoyed this post please click the ‘like’ button above ;)

Add your comment...

Related Posts

(All Etc Posts)

(Published to the Fediverse as: Top 5 reasons to hate the Facebook like button #etc #facebook #like #lessig #dublincore #semanticweb #opengraph #metadata Why can't you link to an existing page? How can you have a like button per blog post on your home page? Are we headed towards a world with only one verb? )

Reviews and links for April 2010

By Robert Ellison. Updated on Friday, May 22, 2020.

The Spire by Richard North Patterson

3/5

A good enough holiday read and nice to see Patterson return to a straight psychological thriller rather than the last few OpEds loosely wrapped with some plot.

 

Advanced .NET Debugging (Addison-Wesley Microsoft Technology Series) by Mario Hewardt

5/5

Comprehensive introduction to low level .NET debugging - when you need to fire up WinDbg to check out the state of the managed heap, or debug a crash dump from the field you'll find this book invaluable. I wish it had been available when I started figuring out how to use SOS.

 

The Complete Stories of J. G. Ballard by J.G. Ballard

5/5

Wonderful collection of all of Ballard's short stories. It's a huge book with surprisingly few duds. My favorites include The Illuminated Man, clearly the inspiration for The Crystal World, which includes meaning bombs like "It's almost as if a sequence of displaced but identical images were being produced by refraction through a prism, but with the element of time replacing the role of light." and The Ultimate City (which isn't using ultimate in the sense of being good...). I've read most of Ballard's novels but not many of the short stories before. They're well worth the time.

 

Links

- Microsoft Agrees With Apple And Google: “The Future Of The Web Is HTML5″ from TechCrunch (Which makes it all the more tragic that a huge number of clients will still be running IE6 :().

- Comedian criticises BBC 'rebuke' from BBC News | News Front Page | World Edition (The problem isn't that it was anti-Semitic, it's that it wasn't funny.).

- UK 'has a high early death rate' from BBC News | News Front Page | World Edition (That'll be the deep fried mars bars and chips.).

- Oklahoma, where women's rights are swept away from All Salon (Competing with AZ to be the most fucked up state? Sigh :().

- Cameras capture 'Highland tiger' from BBC News | News Front Page | World Edition (Tabbs was bigger than that (a house cat)).

- MI5 dumps staff lacking IT skills from BBC News | News Front Page | World Edition (MI5 has staff without computer skills?).

- The Internet Provides. from jwz (Disturbing).

- Who Really Spends The Most On Their Military? from Information Is Beautiful (Click through to the Guardian blog post, interesting reading.).

Add your comment...

Related Posts

(All Etc Posts)

Loose Lips...

By Robert Ellison. Updated on Saturday, October 1, 2022.

XamlParseException and 256x256 icons

By Robert Ellison. Updated on Saturday, September 29, 2018.

When testing out a WPF app on XP I got an unhelpful XamlParseException error report. 

I was a little puzzled because I was hooking up error reporting in App.xaml.cs:

My error handler was attempting to create a XAML window to report the error, and evidently this was bombing out as well triggering the good doctor Watson. I added a MessageBox call instead and discovered that the XamlParseException was wrapping a FileFormatException and the stack trace indicated that the problem was with setting the icon for the window. After removing the icon the app started up fine. Weird.

It turns out that WPF chokes on a compressed 256x256 icon on XP and Vista (Windows 7 seems to cope fine). Saving the icon without compression fixes the problem. I use IcoFX and you can set this at Options -> Preferences -> Options -> Compress 256x256 images for Windows Vista. Of course the consequence is that the icon is a couple of hundred kilobytes larger.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: XamlParseException and 256x256 icons #code #xaml #wpf #wtf You can't use a compressed 256x256 icon with WPF but you can include an uncompressed version. )

Space and multibyte character encoding for posting to Twitter using OAuth

By Robert Ellison. Updated on Sunday, April 9, 2023.

I've spent the last day learning how to use OAuth and XAuth to post to Twitter. There are rumblings that Twitter will start to phase out basic authentication later this year, and more importantly you can only get the nice “via...” attribution if you use OAuth (for new apps, old ones are grandfathered in).

I coded up my own OAuth implementation, referring to Twitter Development: The OAuth Specification on Wrox and the OAuthBase.cs class from the oauth project on Google Code. Both are great references, but both fail with multibyte characters. The problem is that each byte needs to be separately escaped. OAuthBase.cs encodes characters as ints rather than breaking out the bytes and the Wrox article incorrectly suggests using Uri.EscapeDataString().

Here's a method to correctly encode parameters for OAuth:

NoEncode chars is a list of the permitted characters:

An impact of this encoding is that spaces must be encoded as %20 rather than plus. I was worried that each space would end up counting as three characters towards the 140 character limit. I tested this and it isn't true, so use HttpUtility.UrlEncode() to calculate the number of characters in the post OAuthUrlEncode() or similar to actually encode post parameter.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Space and multibyte character encoding for posting to Twitter using OAuth #code #twitter #oauth #xauth How to encode spaces and multibyte characters when posting to Twitter via OAuth / XAuth. )

Reviews and links for March 2010

By Robert Ellison. Updated on Friday, February 24, 2017.

Juliet, Naked by Nick Hornby

3/5

Classic Hornby. It's fairly close to High Fidelity with it's themes of love and music obsession-ism and so feels slightly too comfortable but certainly worth a read if you're a fan. 3/24/2010 2:00:00 AM

 

The Girl with the Dragon Tattoo (Millennium, #1) by Stieg Larsson

3/5

Slow, but highly atmospheric mystery. The first half of the book is dedicated to setting the scene and then the pieces start to fit into place like a glacier melting. The pace makes the occasional punctuation of extreme sexual violence all the more shocking. Fun enough, so I'll probably read the rest of the trilogy and try to catch the film (which has to be a profoundly truncated version).3/22/2010 2:00:00 AM

 

Practical WPF Charts and Graphics by Jack Xu

4/5

Be aware that this book is 90% code, 5% mathematics and 5% explanation. This isn't a criticism, Dr. Xu builds up a complete charting library that includes 2D, WPF 3D and manual 3D methods. The mathematics covers the theory and practice of 2D and 3D transforms as well as techniques for smoothing, interpolating and trending data. It's a fast read to get a sense of the content and then a great reference work to dip back into as needed. 3/14/2010 3:00:00 AM

 

C# Design and Development: Expert One on One by John Paul Mueller

1/5

This book is just atrocious. Each section sells itself as providing all the information you need about a certain topic, then provides trivial and often incorrect or at least highly subjective details. A couple of examples:

The chapter on error handling makes the point that you should catch the most specific Exception possible, but then goes on to demonstrate catching a FormatException, a DivideByZero exception and then just System.Exception. The whole point is to avoid catching Exceptions that you can't handle. There's a legitimate debate here between trying to plaster up the cracks with general catches and letting the application die with a useful stack, however this book doesn't discuss it. There's also very brief coverage of creating your own derived Exception but it doesn't touch on serialization.

Serializing an XML file is somehow included in the section on "Special Coding Methodologies", and labors over calling both .Flush() and .Close() on a StreamWriter. Despite the fact that you only need to call Close(), and that StreamWriter is IDisposable and so a using statement is really the way forward for this example.

I could go on, but won't. Avoid. 3/8/2010 2:00:00 AM

 

Links

- Dorothy Erskine Park Exists from Spots Unknown (Must go find this park.).

- Casttoo from jwz (I want to break my arm again...).

- Woman murdered over Facebook photo from BBC News | News Front Page | World Edition (Somehow I don't think the photo being on Facebook was the important part of the story...).

- Petition against Pope's UK visit from BBC News | News Front Page | World Edition (A better petition would be to get the Pope and Dawkins together on Question Time.).

- 'Heart risk' at football stadiums from BBC News | News Front Page | World Edition (Surprisingly few are equipped to remove gall stones as well.).

- Postal Service's emerging model: Never on Saturday from SFGate: Top News Stories (How about once a week. While you're at it recycle the junk at the post office and don't bother hauling it out for delivery.).

Add your comment...

Related Posts

(All Reviews)

Email marketing - don't shoot yourself in the foot

By Robert Ellison. Updated on Friday, February 24, 2017.

If you send email to customers it's important that you let them know where the email will come from and then use then use this address consistently. Using different email addresses is a recipe for getting trapped in spam filters. This is equally important for marketing and other messaging like bills and canceled flights.

I bring up flights because I'm flying to the UK later today and was planning to return on Sunday. British Airways' Cabin Crew is going on strike this weekend and my return flight has been canceled. Instead of sending a text message BA tried to notify me by email. This would have been fine if they used the address they've used for years, but instead they used a new address and a new domain. In fact in the process of canceling and re-booking I (eventually) got email from britishairways.com, my.ba.com, email.ba.com and pop3.amadeus.net.

Since I've had the same email address for twelve years now I get a fair amount of spam. I use SpamArrest to keep myself sane:

94.9% of my email is spam. Since I started using the service SpamArrest has eaten 482,494 messages for me. I'm far from alone in using white list based email filtering so if you want your message to get through transparency and consistency are the way to go.

Add your comment...

Related Posts

(All Etc Posts)

(Published to the Fediverse as: Email marketing - don't shoot yourself in the foot #etc #britishairways #spamarrest #spam #email Transparency and consistency are important when sending email. Let the customer know where the email comes from and always use the same address. )

Is Intuit Insane?

By Robert Ellison. Updated on Wednesday, February 22, 2017.

Yes.

Some more color. I use Intuit's assisted payroll service, which is fantastic. You run payroll straight out of QuickBooks and Intuit handles all the tax disbursement and filing for you.

I got an email today with an attachment called securedoc.html claiming to be a message from Intuit. The idea is that you open the attachment and then login to view the message.

It really couldn't look any more like a phishing email, however I called Intuit and remarkably it's a real message. They seriously expect me to open an email attachment and provide account information. The support person at Intuit was able to read the message to me and it was just a routine acknowledgment that some tax rates had been updated.

Intuit is seriously training its customers to fall victim to phishing attacks. The right approach would be to say that a message is available and to log in to your account to retrieve it, or better still to send a message through the existing system in QuickBooks. Securedoc.htm is just begging customers to provide their account information to the bad guys.

Intuit's payroll service stores bank account information, employee Social Security numbers and other data that you really don't want to expose. If you're an Intuit Payroll customer please call and complain. If you've received one of these messages I'd also recommend forwarding it to [email protected], their address for reporting phishing attacks. 

 

Add your comment...

Related Posts

(All Etc Posts)

(Published to the Fediverse as: Is Intuit Insane? #etc #spoof #phishing #intuit #quickbooks Intuit is training its customers to fall victim to phishing attacks by sending messages using securedoc.html )

Reviews and links for February 2010

By Robert Ellison. Updated on Friday, February 24, 2017.

Programming WPF by Chris Sells

4/5

A highly detailed and well written reference to WPF. Note that this second edition is still based on Visual Studio 2005 / .NET 3.0 so a little out of date now. I still found the book to be very useful and would recommend it both for picking up WPF basics and to refer back to for more advanced topics when needed.2/26/2010 2:00:00 AM

 

Professional C# 2008 by Christian Nagel

4/5

I'm in the process of upgrading to VS2008 and loved the 2005 version of this book so picked up the 2008 update. It's a broad language and framework reference, perfect for understanding what's available in .NET 3.5 and how to get started. My only complaint is that it could have used a "what's new" section or guide to separate out completely new technologies from those familiar from .NET 2.0. Not a big problem though, it's easy to skim through the old stuff and then pay attention when you reach something new. I'll probably pick up the 2010 version in 2015 or so ;)2/15/2010 2:00:00 AM

 

Links

- UK NHS urged to buy Fairtrade tools from BBC News | News Front Page | World Edition (Fair enough, but what about having developing countries pay to train doctors and nurses and then poaching them to work for the NHS?).

- Brown 'upset' by bullying claims from BBC News | News Front Page | World Edition (And when he finds those responsible he's going to turn purple, squint and twat them.).

- CBS runs free ad for "magic" energy box from Boing Boing (A slightly more skeptical take. Magic box plus natural gas...).

- French halal burger sparks appeal from BBC News | News Front Page | World Edition (So eat somewhere else. You're in France and not about to starve.).

- One inch equals $30,000 in online dating world from Boing Boing (I'm worth $2.2 million :)).

- Video: Mantis vs. Cursor from Boing Boing (OK, I need a Preying Mantis to entertain me like this while I work...).

- Toyota recalls 8,000 US vehicles from BBC News | News Front Page | World Edition (And they're not even real propellers. They're just the joke ones you can attach to your tow hitch.).

- Britain reveals how U.S. treated detainee from SFGate: Top News Stories (Miliband against the "principle of their disclosure by an English court against U.S. wishes"!).

- Mariposaaah!!! from Spots Unknown (Feels steeper walking up it.).

Add your comment...

Related Posts

(All Reviews)