Tomer Gabel's annoying spot on the 'net RSS 2.0
# Tuesday, 25 October 2005

So I found myself in the predicament where a particular class I was using had multiple event sources and I was attempting to fire those events. I encountered two issues, the first of which was that I was trying to invoke the delegates from an outside class, which is impossible even though they're public:

An event can be used as the left-hand operand of the += and -= operators (Section 7.13.3). These operators are used, respectively, to attach event handlers to or to remove event handlers from an event, and the access modifiers of the event control the contexts in which such operations are permitted.

Since += and -= are the only operations that are permitted on an event outside the type that declares the event, external code can add and remove handlers for an event, but cannot in any other way obtain or modify the underlying list of event handlers.

(via MSDN)

This means I had to implement an OnEvent() triger method on the provider class for all events, even though the provider class was intended merely as a container and the events were intended to be fired elsewhere (think of a remotable event container and a seperate execution piepline). This meant I had to provide a lot of boiler-plate code in both consumer and provider classes to make use of these events. I would've written a generic method to handle this which accepts a Delegate parameter; enter the second issue: you'll notice that a non-specialized delegate (Delegate as opposed to, say, an instance of AsyncDelegate) does not have a BeginInvoke method. After a little research I've found some inspiration in Eric Gunnerson and Juval Lowy's classic TechNet presentation on C# best practices, however that particular implementation wasn't convenient for my uses, nor was it compliant with .NET 1.1 specifications (which require that you call EndInvoke on any asynchronous invocation to avoid resource leaks). I eventually went on to write a class that'll do the work for me.

The basic idea is to call the delegate's BeginInvoke and EndInvoke methods via Reflection. To invoke a method via Reflection you (obviously) require an invocation target; this wouldn't be an issue if the target hadn't been an event. Apparently the EventInfo class returned by Type.GetEvent() has no provision for obtaining an actual instance; instead, you have to obtain the event instance as though it were a field. Check out the following code:

// Gather requisite Reflection data

private Type m_handler;
private object m_eventInstance;

...

m_eventInstance = target.GetType().GetField( eventName, BindingFlags.Instance | BindingFlags.NonPublic ).GetValue( target );
m_handler       = target.GetType().GetEvent( eventName, BindingFlags.Instance | BindingFlags.Public    ).EventHandlerType;

// Call BeginInvoke

m_handler.InvokeMember(
"BeginInvoke",
BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod,
null,
m_eventInstance,
paraList.ToArray()
);

You can find a complete AsyncHelper class and associated (very minimal) example code here. Note that at current delegates with out or ref parameters are not supported; these could be inferred by Reflection and added to the EndInvoke method call, but I fail to see how calling such delegates asynchronously in a generic fashion would be useful.

Tuesday, 25 October 2005 17:59:40 (Jerusalem Standard Time, UTC+02:00)  #    -
Development
# Sunday, 23 October 2005
I wonder if bitrate is to bits what titrate is to...
Sunday, 23 October 2005 15:44:02 (Jerusalem Standard Time, UTC+02:00)  #    -
Personal
# Wednesday, 19 October 2005
Seen quite a few movies recently. Here's a bunch of stuff:
  • The Life Aquatic is a unique movie. Not quite comedy, not quite drama, it still manages to be interesting, never dull, often hillarious and even moving at times. It tells the (fictional) story of oceanographer Steve Zissou (played by Bill Murray) in his last great adventure: trying to find and kill the shark that ate his life-long friend Esteban. Although this may sound like a modern-day Moby Dick, the rest of the movie certainly isn't. With an insane cast including Owen Wilson, Cate Blanchett, Anjelica Huston, Willem Dafoe, Jeff Goldblum and Michael Gambon this movie seemed to have faded into obscurity simply because it is so odd and unusual most people simply can't figure it out. Recommended.
  • Versus is a Japanese action flick which includes Yakuza, zombies and supernatural forces. Despite terrific action scenes and some amusing characters (particularly the, er, protagonist) it completely fails to mesmerize; unlike some of its Chinese counterparts (such as Black Mask) the movie doesn't flow, it just drones on and on into monotony. Stay away.
  • Four Brothers is the story of, well, four unlikely step-brothers (two white, two black) whose mom is shot down by gangsters and they seek revenge. Although the base plot is pretty standard fare the movie itself is very well made; it reminded me strongly of The Boondock Saints (itself a highly recommended movie). Four Brothers isn't quite as good but still works very well and manages to combine comic relief with some drama and lots of action. Recommended.
  • Dodgeball: A True Underdog Story is a hillarious movie with Vince Vaughn and Ben Stiller. I usually dislike Stiller intensely, but in this particular case it works very well. The (relatively stupid) plotline pits Peter La Fleur (Vaughn) as a proprietor of Average Joe's Gym, a gym for people just like you and me (well, not really - I hope I'll never be as pathetic) facing foreclosure, against White Goodman (Stiller), owner of Globo "We're better than you, and we know it!" Gym who's trying to take over Average Joe's. Fast forward a bit, you got the guys at Average Joe entering a dodgeball tournament to win a reprieve from Average Joe's mounting debts; Rip Torn in one of his most bizarre and hysterical roles yet; great actor chemistry and goofball humour which all adds up to a really fun movie. It's not quite as good (or satirical) as BASEketball but it's great fun never-the-less.
  • I saw the first two episodes of Planetes and couldn't figure out what the big deal was; my brother (who usually knows his stuff) spoke very highly of the series but the episodes I watched bored me so badly I stopped watching in the middle, instead preferring to finish playing The White Chamber.
  • In other news, Serenity will be coming to Israeli theaters sometime in mid-November. Hoozah! Since the tickets to the screening at Icon were long gone by the time I tried to order this means I might yet get the chance to watch the movie, and might even do some catching up on Firefly beforehand.
Wednesday, 19 October 2005 12:12:19 (Jerusalem Standard Time, UTC+02:00)  #    -
Movies
# Monday, 17 October 2005
Here's today's tidbits. I don't have much time so I'll keep the list relatively short (it currently amounts to about 10% of the stuff I have in my "pending" file):

    Development

  • Here's a bizarre trick (via Ayende): apparenly when binary-searching an array (via Array.BinarySearch) if the specified value is not found, you can get the index of the next largest value by bitwise-complementing the result (index =~ index;). Convoluted, but useful.
  • Here's a cool shell extension improvement from Jeff Atwood called Clean Sources Plus (based on the original codebase by Omar Shahine); it allows you to "clean up" a VS.NET solution from intermediate files and source control bindings for sharing with other developers. Dead useful.
  • Fascinating discussion in response to Jeff's post about eliminating the user field from login screens. Personally I don't think there's anything wrong with the current system (I read the post too late to participate meaningfully in the discussion), but there's a lot of interesting stuff to read there.
  • Nifty demonstration of basic CSS 1.1 and JavaScript. It doesn't work in Internet Explorer because IE does not support alpha in PNGs (a very annoying limitation in itself) and does not fully implement DOM events.
  • I stumbled upon an old article by Joel, which states something so absolutely obvious most people completely fail to realize it: people (and programmers specifically) are only very good at doing one complex thing at a time. Giving a programmer (even a good one) more than one project, or alternatively interrupting his project for "right here, right now" kind of work, is hazardous to his or her productivity. It reminds me of Fred Brooks' excellent The Mythical Man-Month; in retrospect the conclusion is just so obvious it seems almost impossible that people didn't realize it at the time.

    Stuff

  • DARPA challenge finally beaten! This is a huge event for robotics fans, which I'm not - however I recognize that this is a landmark in AI and robotics. Impressive stuff.
  • My next keyboard is probably going to be the new Microsoft Natural Ergo 4000. I intensely dislike most keyboards out in the market these days (still use a Microsoft Natural Elite or IBM Model M) and it would be a nice change of pace to get a new Natural with added features (padded wrist-pad, standard page-up/down cluster etc.) which doesn't suck. I hope the tactile response is at least as good as the Elite's. I was looking to get one of those, but apparently only Dagesh carry those in Israel so far (for 380 shekels, shipping included ~ $75 + VAT); I would get it from eBay, but it won't cost any less and it's a warrantee nightmare. Guess I'll just wait.
  • Here's an interesting concept: labs.zarate.org allows you to create passwords on a per-site basis by providing a master password and target URL. It works by MD5-hashing the master-password with the site URL. Cool idea and seemingly quite secure (assuming the hashing function is strong enough; considering the general quality of passwords people use, I'd say it's about 1,482,918 times better).
  • The Flying Spaghetti Monster is apparently old news, but completely hysterical never-the-less, particularly in today's age of religious zealots and their "intelligent design" dogma.

    Politics

  • Assuimg this article is to be believed, post-Taliban Afghanistan is about to put a journalist on trial for charges of blasphemy. You'd think that the US with its self-proclaimed desire to bring democracy to the world would not have left a radical Islamic government in Afghanistan. You'd be wrong.
  • UK Labor party member Walter Wolfgang, 82, was forcibly ejected from a conference for heckling the foreign secretary. This in itself is common in stupid political strife; what worries me is that a second delegate (Steve Forrest) who protested the treatment was also forcibly ejected and then denied access to the venue under the powers of the Terrorism Act. If said act can be used to circumvent lawful political activity by democratically-elected public officials, I cringe at the thought of what kind of power it gives the police over, say, an ex-Israeli army officer visiting London.
  • A Delaware public official lost in court against an anonymous blogger who posted what said official perceived were defamatory comments against him. The court ruled that the blogger's ISP may not expose his identity, which I consider a major win for free speech. Too bad other courts are not quite as sensible.
Monday, 17 October 2005 13:56:29 (Jerusalem Standard Time, UTC+02:00)  #    -
Personal
# Sunday, 16 October 2005
About a month ago I invited a bunch of people to an impromptu LAN party to be held at my parent's house (as they were out of the country at the time). Despite some organizational hurdles (primarily the lack of a network switch with enough ports) we eventually managed to overcome the party was sweet, short and to the point.


Omer playing StarCraft

During the course of about 20 hours we played loads of Call of Duty, some StarCraft: Brood War, a bit of WarCraft III and a whole lot of my personal favourite: UT2k4. UT flavours included regular deathmatch, quite a bit of Onslaught (not my favourite of gaming modes, but nevermind that), a little bombing match and what I consider the best gaming-mode: instagib deathmatch. It's hillarious, and you can't beat the andrenaline rush (well, except maybe Q3 DM17 with 5 bots at hardcore).


Myself, concentrating on a round of UT

As usual we saved StarCraft for the wee hours of the night. The two games I played prove that I can still hold my own; my personal preference is for team melee where I control base contruction and expansion at first and combat later, with a second player supporting me on construction and exploration at first and maintenance later. I find that I'm extremely capable when it comes to fast micromanagement but am terrible when I have to do more than one big task at once (for example managing combat while micromanaging fleet construction). Playing with my brother that way was an extremely effective combination and we took the game by a large margin, which was very satisfying.


Oren next to Call of Duty

My personal forté is first person shooters though, so it's no surprise that's what I played the most (I couldn't be bothered joining in on WarCraft III). We played Call of Duty and UT2k4 for several hours each; Call of Duty proved to be an excellent multiplayer game, but only if there are a lot of players in the game. 8 players are enough for a good game, but say 5 or less simply aren't enough to keep the action up and the game becomes very dull indeed.

I wish I could convince the others to give Tron 2.0 a multiplayer spin, but other than that I don't even know where to start in looking for good multiplayer games. Halo proved to be a big disappointment for me (way too slow - not in performance but in gameplay - and too much emphasis on vehicles) and trying Counter Strike: Source for a bit only strengthened my resolve not to play tactical shooters.

Sunday, 16 October 2005 18:29:16 (Jerusalem Standard Time, UTC+02:00)  #    -
Gaming | Personal
# Tuesday, 11 October 2005
Am I the only one going insane over the time it takes for the average IDE to load these days? It takes Visual Studio 2003 up to ten seconds from click to functionality, and with ReSharper installed (which I consider a must-have) it takes ever longer. In the days of multiple-gigaherz machines with multiple-gigabytes of RAM and souped-up, quad-rate busses, why the hell do I have to wait for my development environment to load?

Mind you, VS2003 is not the worst of the bunch; Eclipse used to be the slowest-starting app I've ever seen up until version 3.1. Now it's more or less on par with VS2003. NetBeans lags behind in the performance department. Looking at the VS2005 beta 2 (I haven't tested the RCs) it looks like Microsoft has improved performance - at least startup performance - drastically. I certainly hope that's the case. Since I usually work with 3 or more instances of VS2003 open concurrently any improvements to its performance or memory footprint would be welcome in the extreme.

Tuesday, 11 October 2005 09:38:16 (Jerusalem Standard Time, UTC+02:00)  #    -
Development
# Sunday, 09 October 2005
A product I'm working on consists of a primary component and two sattelite components. The sattelite components are designed to run remotely and communicate with the primary component via .NET Remoting. The product is currently undergoing a QA cycle, and the QA team had a bizarre issue to report: when the system is configured to run on localhost and the network cable is disconnected while the system is up and running, remoting requests fail (they reported that the primary component fails to notify the satellite component instances to shut down, but it was actually the same with any remote call). My immediate response was "huh?" but subsequent local testing assured me that they weren't smoking anything illegal.

After quite a bit of research (this is a seemingly little-known issue with .NET Remoting) I managed to come some interesting insights into .NET, but only one relevant post I managed to find after playing with Google Groups a bit: apparently when Windows detects a network cable disconnect (via a feature called Media Sense) it "removes the bound protocols from that adapter until it is detected as "up" again". The only workaround I could find was to completely disable Media Sense, which needless to say is a very unwelcome solution.

I suppose the obvious question is "why the hell does Media Sense shut down localhost connections?" I'm often dumbfounded by bizarre design decisions in Microsoft products, but this one may just necessitate adding a really awful hack to our installation procedures on clients' sites, which just sucks.

Sunday, 09 October 2005 15:02:05 (Jerusalem Standard Time, UTC+02:00)  #    -
Development
# Thursday, 06 October 2005
And now for the rest of it.

General Stuff

  • The Deer Park (Firefox 1.5) beta has been out for a couple of weeks now and is very stable and fast; beta 2 is due to come out any minute now. Despite the lack of a compatible Noia 2.0 eXtreme (my favourite Firefox theme) I highly recommend the upgrade.
  • Fasterfox is a major performance tweak for Firefox. We don't have the fastest internet connection here so it's difficult to tell how effective it is, but I'll try and gauge it over the next few days anyway.
  • Metal Gear Solid fans owe it to themselves to hear virt's remix titled My Frequency Is 140.85.
  • Martin of Tipmonkies (heh. Tipmonkies. Heh.) published a list of free disposable e-mail address services. My personal favourite is DodgeIt.
  • Finally, Serenity seems to be doing rather badly financially. I haven't seen the movie yet (and I doubt I'll get to see it in the Israeli theaters, with all the crap movies taking valuable theater space) but I have a very good feeling about it, and I hate to see anything original, interesting or (in Firefly's case) underdog do badly.
  • Mystified by Virgill is awesome. For that matter, so is elements. The guy knows his shit.

Politics

  • It bothers me a great deal when American agencies (or goverment agencies in general) presume to tell me what I'm entitled, or not entitled, to. As far as I'm concerned the default should be "I can do whatever the hell I want as long as it's not declared illegal", not "I can do whatever is declared legal". Very important distinction. So it's no surprise I was really pissed off to read an FCC document in which a statement began with "consumers are entitled to run applications and use servics of their choice". Thanks! I always wanted a government to officially allow me the liberties I've always taken for granted. But that's nothing compared to the rest of the statement: "... subject to the needs of law enforcement." You know what? To hell with the needs of law enforcement. I won't have police/FBI/shabak/whatever goons telling me what programs I can or can't use. I realize that it's like that in practice (the old issue of >128-bit RSA encryption not allowed outside the US, for one), but it's no excuse to make it official policy. I'll run whatever the hell I want on my machine. If it's illegal, have the police come up with sufficient justification for a search warrant, signed by an independant judge.
  • The US Patent Office upholds a patent owned by Eolas, which has bearing on their case against Microsoft. I don't know the details of the patent and don't care. Ideas and thoughts should not be patentable, as simple as that. As Florian Mueller puts it (direct quote from the linked article):
    Pro-patent politicians told us that broad and trivial patents can be invalidated. If even Microsoft with all of its resources doesn't always succeed in that, what can smaller companies do?
  • Apparently a single, disabled mom has found the strength to sue the RIAA back for wrongful legal practices. Any dent in the RIAA litigation behemoth is a good thing in my book.
  • An ISP owner from Oklahoma wins a $10M lawsuit against a known spammer. It's doubtful he'll be getting any of his money, but the precedent-setting case is good in the long run anyway.
Thursday, 06 October 2005 15:55:14 (Jerusalem Standard Time, UTC+02:00)  #    -
Personal
Seeing that I don't have anything of value to write per se (with the exception of experiences from the LAN party, and Turkey, and a bunch of reviews, and some development-related rants, and some other stuff) I figure I might as well just toss everything I have here. There's quite a bit of development-related stuff so I've split this into two seperate posts:
  • Ilya linked me to this newsgroup discussion which is something of a revelation.
  • During the QA cycle for a product I'm working on I got a request to limit the logs for just the last 10 days. I use log4net 1.2.9 incubation release, which is an absolute pleasure to use (even the documentation is up to snuff these days); however I've found that there is simply no way to do that using the stock RollingFileAppender when you roll by date (as opposed to by size). Since I didn't have time to research creating scheduled tasks using the godawful Visual Studio 2003 Setup and Deployment Project I just hacked a RollingFileAppender-derivative, only to find that most of its protected methods are not declared virtual - meaning I had to copy the code for the class in its entirety and hack away instead of just inheriting and overriding behavior. If anyone's interested in the hack let me know, but be advised that it's probably not very stable nor particularly elegant.
  • I was looking for a way to execute an interactive process remotely (which can't be done easily, certainly not with my original research subject, WMI). Apparently the only practical way to do this under Win32 is to use a remote service with administrative privileges; security was a workable issue in this case, so I was left with having to research and write the service and deal with all the bugs, which given the project schedule was not an option. The first obvious option was to use SysInternals' PsExec tool; this would've been perfect except that PsExec's license forbids redistributing it without a license, which we were very inclined to purchase had there not been easier (and cheaper) options. BeyondExec is an equally solid solution that's distributed as freeware and is therefore useful for commercial purposes. Lastly, Jim Wiese has an interesting article up at The Code Project which might've saved us a great deal of time had BeyondExec proved irrelevant.
  • John Wood's SafeInvoke is a very elegant solution to the classic GUI thread invocation issue when programming for Windows Forms. He's not the first to utilize .NET Reflection for that purpose, but his solution is extremely elegant as well as performant (since his helper class caches the generated code, a performance hit is incurred only when a delgate is first used, and System.Reflection is supposed to be dramatically faster in the upcoming CLR 2.0). Two thumbs up.
  • One of my favourite writers, Reymond Chen over at The Old New Thing, wrote an insightful little tip on why you should never use sleep(0). The comments are equally informative. On a side note, I've recently become a very big fan of java and C#'s Monitor synchronization primitive along with its signalling capacity (in java it's part of the java.lang.Object API
  • , which is much more elegant than C#'s Monitor class and its static members).
Thursday, 06 October 2005 15:04:30 (Jerusalem Standard Time, UTC+02:00)  #    -
Development
# Sunday, 02 October 2005
Damned if I know why, but the Call of Duty 2 demo sucks. Oh, I can describe the symptoms alright, but there's a fundamental problem there that eludes me. Why would a sequel that's seemingly based off of the same (extremely good) codebase as its predecessor not be able to compete in visuals and performance with two year-old games?

Now don't get me wrong, I'm as big a sucker for visuals as the next guy (if not more so), but although the CoD2 screenshots look pretty sweet there's nothing there to take the visual acuity crown from either of the games I mentioned above. There's certainly nothing to justify a former hi-end machine - AthlonXP 2800+, 1GB RAM, Radeon 9800XT - grinding to unplayable framerates at low resolutions (about 20 frame per second at 640x480 with most everything turned either off or low) or having decimal-point framerates at high resolutions (0.2-0.5 frames per second at 1024x768 with medium-high details and no antialiasing). The same machine plays Doom 3 and Half-Life 2 at 1024x768 with x4 AA and crunches frames like there's no tomorrow. To reiterate, both games look considerably better than CoD2.

On a radically different note, I managed to miss the fact that the Serious Sam II demo is out. I'm downloading it and will report when I get the chance to play it. Indigo Prophecy is out too, so I guess my current playlist reads something like:

Guess I gotta get some spare time on my hands...

Sunday, 02 October 2005 13:23:04 (Jerusalem Standard Time, UTC+02:00)  #    -
Gaming
Me!
Send mail to the author(s) Be afraid.
Archive
<2005 October>
SunMonTueWedThuFriSat
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345
All Content © 2017, Tomer Gabel
Based on the Business theme for dasBlog created by Christoph De Baene (delarou)