Wednesday, September 28, 2005

SafeInvoke: Making GUI Thread Programming Easier in C#

John Wood has written a pretty tricky and seemingly very helpful solution to call methods on UI controls easily (as in – much lesser code).

You know the problem: if you want to call a UI component’s method in a thread-safe manner, you must use the Invoke (or BeginInvoke and EndInvoke) method. In addition, you need a delegate and a special method for every such method you call, and then you have to do that again in each project! (I’m not talking about C# 2).

I’ve seen various ways people have tried to work around this painful bit, but I think that John’s looks particularly nice.

Performance-wise, for a single call it may be too expensive since it’s based on Reflection, but in most cases those calls are performed again and again and since he uses a caching mechanism I wouldn’t worry about that.

I’m certainly going to try it out next time I need it!

Ah, I almost forgot, here’s the link:



Sunday, September 25, 2005

Back to the basics - recursive iterators

Stephen Toub did it again!

He’s posted a series of 3 posts on recursion versus iteration with C# iterators. Although it’s really basic, it’s important to be reminded of the cases where the difference in performance should be considered and how to do it.

Part 1:

Part 2:

Part 3:



I'm back

Well, moving is really a pain. I never remembered how hard it is (guess it's my selective memory).
Anyway, I'm back working, with a much more adequate working space, which is really nice.

I know I've promised a well-performing pseudo-Activator (a.k.a. DynamicClassFactory), but I haven't finished polishing it for publishing yet.
Since I currently have to get some work done, this post will have to be delayed a bit.

I need to use a well performing replacement for the ListView control. It will be used in a sort of online logging mechanism, so I need it to be able to cope with a very large number of items (and items are being added very often). Actually, it should have a cyclic buffer - very old items are really irrelevant, so there is no need to keep them in memory.
I'm looking for something that could give this functionality. The best would be if the buffer size was configurable, but could perform well even with a very large buffer.
I have a few ideas how to implement it such that it would provide optimal performance, but I'm trying to avoid it. I'll Google for it a bit and see what I come up with. I'll send a follow-up post on this with the results.

Monday, September 12, 2005

Where am I?

Next Sunday we are moving. Besides, I've been pretty sick for the last couple of days (somewhere between really bad allergies and the flu) and it doesn't seem to be getting better.
So I will most probably get back to blogging in a week or two, after I get things in order in the new house, and hopefully I'll also feel better.

Thursday, September 08, 2005

Israel Visual C++ Users Group September Meeting

Israel Visual C++ Users Group September Meeting


Date:    Wednesday, September 21, 17:00 - 20:00

Place:   Microsoft Israel 

            Hapnina 2  (Amdocs Building)

            Ground Floor


+972 (9) 762-5100         


Parking is parking available at the Kurkar parking lot. Proceed straight past the traffic circle and the parking lot will be on your right.


Topic: Microsoft TCP stack implementation

Lecturer: Arkady Frenkel, Windows SDK MVP


In this presentation, Arkady will define how the OSI (Open Systems Interconnection) model is implemented in the desktop Windows operating systems (which exclude the Windows CE TCP stack).

Arkady will describe all the levels of the TCP stack; from the Layered Service Provider to the miniport layer of Network Driver Interface Specification (NDIS). He will cover the communication interfaces between layers.

He will show and analyze the Networking API (pipes, mailslots, winsock, RPC, Netbios, CIFS) as clients of the TCP stack on the application layer.

Name Resolution and binding will be reviewed too, as they are important aspects of networking.

Arkady will provide examples of what can be done using the Platform SDK and DDK.

If time allows, WMI and IPHLPAPI will be discussed as additional help subsystem for Windows networking (with code examples).


For nearly 25 years Arkady has been developing Wired and Wireless Real-Time Industrial Control Systems (SCADA). The environments include the RTE (Real-Time Executor) OS on HP 21xx and RT11, RSX on PDP-11. Fourteen of those years include experience with all versions of Windows (including all version of Windows CE from first the version till CE.NET).

His areas of interest have always ranged from low level kernel and drivers to GUI based user applications, using MFC, COM, and ATL.

He is familiar with the TCP stack from Winsock through LSP and the NDIS protocol and IM.

Last year he was offered a development position writing NDIS Wireless miniport drivers. He now works for Rokonet, a leading provider of comprehensive security solutions worldwide, developing UPnP solutions for its controllers in .NET (C#).


Arkady was awarded the Windows SDK MVP in 2001.

Although admission is free and you may attend without reserving a place, we kindly request that you notify us if you plan to attend so that we can be sure to have enough chairs and FOOD!


Thank you.


Moshe Raab


See more info at:


Demistifying events

I ran today into a really annoying constraint regarding events. It is known as error CS0070, and says that events can only be invoked from the class in which they were declared. So even if you have a protected event (with public accessors to add/remove listeners) in a base class, derived classes can not directly use that event.
Googling a bit on this issue (mostly to find other people complaining about it, 'cause it was pretty clear that's the way it is and there's nothing I can do about it), I came accross a pretty nice post that could help explain some of the issues with events that are not all that clear in MSDN. I haven't read it from top to bottom, but from the skimming I did it looks pretty good. Enjoy!
C# events vs. delegates

Wednesday, September 07, 2005

.NET Performance Benchmarks

If you're having some code doing intensive mathematical calculations, I suggest you go check Wesner Moise's benchmarks:
Decimal Performance - Note the horrible performance of the Decimal datatype
Math Functions Performance - Note the difference between x*x and Math.Pow(x,2). How did this pass QA???

Thanks to my friend Gil for pointing these out to me.

Tuesday, September 06, 2005

Now that's how a software company should work!!!

I've been using JetBrain's ReSharper for a couple of weeks now, and I'm really pleased. I was used to Visual Assist and in my opinion there is no real competition between these two - ReSharper is clearly several leagues higher.
But, that's not what I was most impressed about. I soon found out that one of the features I used a lot in Visual Assist did not exist in ReSharper. I'm talking about multiple clipboards - the last few things you copied to your clipboard are all memorized, and with a few keboard strokes you get the list of last things on your clipboard and you can choose which you want to paste. A real coding-time saver. I was really sad - such a good tool and this particular little thing I am so fond of is missing. So I followed Tomer Gabel's recommendation and filed an RFE with the JetBrains guys. A week later, they sent me a message, asking me how I thought this feature should work. Another week later I got a message that the feature has been implemented in build nr. 206.

Did you get that? In 2 weeks they implemented a new feature, they didn't event intend to have in their next release, only because one potential customer has asked for it!!!!
Well, now I'm decided - I'm buying it!!! Not only I have that one feature I was missing, but I'm confident that the software will always be as cutting-edge as possible.

Fellow programmers/team leaders/project managers/etc. - that's the spirit!!!

Where I've been + a Barbecue Booster

Things that really matter - I haven't been very blog-active lately. My sister came from the States with her little son, so I spent some time with them and didn't have any left to blog...

Last week-end we had a family barbercue, and I used an old recipe to spice chicken (it is originally for chicken brochettes, but I used it for wings with tremendous success). I've been using this recipe for several years, and each time people keep talking about it for weeks after the barbecue. It's not my invention, but I don't remember where it came from...
So here's the things you should mix to put on around 2kgs of chicken wings. I suggest you let the wings rest a couple of hours in the refrigerator before putting them on the fire, so the tastes would be better impregnated.
Of course, the quantities are rough approximations and should be altered to suite your own taste.

  • Paprika (sweet, not hot) - 3 table spoons
  • Crushed Chili Pepper - 1 tea spoons
  • Cumin - 3 tea spoons
  • Cinnamon - 1 to 2 tea spoons
  • Nutmeg - 1 to 2 tea spoons
  • Crushed Garlic - 3 tea spoons
  • Lemon Juice - of 2 to 3 fresh lemons
  • Ground Black Pepper
  • Salt
  • Olive Oil - about 1 cup

You mix it all thoroughly and make sure all parts of the chicken are fully smeared with this stuff. After a couple of hours, put it on the barbecue and have some of the best chicken wings you've ever known!

I'd be glad to hear how it went...