Archive for January, 2011

An IProducerConsumer that does not work with the BlockingCollection

January 26, 2011 Leave a comment

Providing progress updates is a problem that many
applications have to deal with. As users, we like seeing that the computer is
working on our behalf and isn’t stuck. Something which adds a layer of
complexity to the providing updates problem is that a background thread is
normally the thread doing work, and the GUI thread is the thread that paints
the message/status for the user to see. So the hand shaking between the worker
thread and GUI thread is something which needs to be managed. It has been the
experience of some programmers that they are able to provide progress messages
so fast that it starts to slow down the GUI, and the background threads are
getting bottlenecked by providing progress updates.

In an attempt to solve this problem generically I wrote a
class which implements the IProducerConsumer interface, but will only ever
contain the latest item added to it. The idea being that background threads can
add progress updates to it at whatever rate they desire, but when the GUI
thread asks for progress, it will only get the latest progress message.

Curious to know if this IProducerConsumer implementation
worked as the underlying data store for the BlockingCollection class, I wrote a
test to see. The test case fails when the consumer thread calls
BlockingCollection.Take(), when three items have been added to the blocking
collection, but only two items have been taken from it. When writing the test
case I was expecting the BlockingCollection to block the thread on the call to
Take() because the underlying data store didn’t have any items in it. The last
item which had been added had already been taken. What happened when running
the test was an InvalidOperationException: The underlying collection was
modified from outside of the BlockingCollection.

At first I found this to be confusing, because the
underlying collection wasn’t modified from outside of BlockingCollection. All
of the calls to add or take items were made through the BlockingCollection. It
turns out that BlockingCollection keeps a count of how many times Add() has
been called and how many times Take() has been called. Since my
IProducerConsumer doesn’t behave similarly the BlockingCollection can’t behave
deterministically. This isn’t spelled out in the BlockingCollection documentation,
but is probably what “The BlockingCollection<T>
can become corrupted if the underlying collection is changed directly.”
is referring to. It is very important for a class like BlockingCollection to
behave deterministically, making it not unreasonable to enforce this behavior.

I was able to verify that BlockingCollection
tracks the number of items it expects the underlying data store to have by
adding a bunch of items to the BlockingCollection and then checking its Count
property. If the BlockingCollection was using the Count of the underlying
IProducerConsumer it would return a value of one, but if it kept its own count
it would return the number of times Add() had been called. The
BlockingCollection returned the number of times Add() had been called.

How to install VSIX project

January 25, 2011 Leave a comment

I read through all of the walkthroughs on MSDN about extending Visual Studio. Let me tell you there are a lot of them. One of the nice features of Visual Studio (at least VS 2010) is that when you are debugging a VSIX project it will automatically launch an instance of Visual Studio with your extension registered and installed in an “Experimental” instance of Visual Studio. This is great. I’m glad the Visual Studio team thought this through.

Tonight I came to the point where I’m pretty confident about my extension and want to actually install it. This way I can use it and flush out any bugs in real life use. I read and read and searched and searched and was not able to find any walkthrough that went through the step of graduating your Visual Studio extension from Experimental to Production. Part of the reason why is because it’s really easy to do. I am now going to spell out how easy it is.

Go to the project output. Next to the extensions .dll and .pdb files will be a .vsix file. Double click on the vsix file to install (register) the extension with Visual Studio 2010.

(I can’t believe I wasted a whole evening on that)

When Rage isn’t so enraging

January 17, 2011 Leave a comment

For Christmas, Amanda and I received Rage. It’s a card game with Uno like cards and kind of plays like Hearts. The premise is that you win a ‘trick’ by laying down the highest numbered card of either the lead color or the trump color. The game is most likely called rage because you might lay down a card, and feel positive as to your win (or in some cases your loss) of the trick, but someone subsequently lays down a card which upsets your confidence of the outcome.

Should you be really confident, and then all of a sudden your upset, you then feel enraged. Amanda and I have played the game three times. Once with my family (where I think there were seven players), once with Amanda’s family (where I think there were seven players) and once with the Wilsons (where there were four players). I noticed something when playing with the Wilsons though, I wasn’t nearly as enraged. I’m not one to hold grudges or start hating another player because they did whats best for their interest, but I will show outbursts of emotions when things suddenly don’t go my way. These aren’t serious emotions, because being melodramatic about games does make them more entertaining. I think the reason why I wasn’t enraged so much is that with four players there’s a lower probability of someone playing a card which would foil my crafty schemes.

The package does say that it’s a game for 2-8 players (and we did calculate at the Wilsons that it can work with 9). I don’t see how it would be any fun with two players, and since I find emotional swings to be the fun part of the game I suggest playing with as many players as one can find. Because if you don’t become enraged at Rage, what’s the point?

Categories: Entertainment, Hobbies

The Dangers of playing Wii with Fire

January 12, 2011 Leave a comment

When the Nintendo Wii was released there were different news stories about how “dangerous” it was. People jumping and waving their arms around might end up hurting themselves, destroying property, or be handicapped with an unrealistic view of their physical prowess. Now that it’s been over four years one doesn’t hear those stories anymore, but perhaps as a society we need to wait for a generation to pass before passing judgment on the unforeseeable consequences of the Wii.

I did find out something interesting the other day, and that is that fire and Wii don’t mix. Sounds like a dangerous combination, doesn’t it? I found this out when playing Metroid: Other M. Amanda decided to light a fire in our fire place. Our couch is situated on the west wall of the condo and the fire place is on the north. Metroid is a game where the Wiimote moves from a classic style D-pad on the left held horizontally position, to standard point at the screen, during the entire game. I was really frustrated when playing and it seemed like the Wii was having trouble making up its mind about the direction the Wiimote was pointed, which really interrupts game play. I changed Wiimotes and the problem persisted. I had a little thought and stopped playing to wait for the fire to die down.

Surely enough, a few hours later, the fire had died down and Metroid was back to being an awesome gaming experience. The morale of the story is that one should not play the Wii with a fire on their left.

Categories: Entertainment

Glorious Basketball career

January 9, 2011 Leave a comment

On Thursday my ward had their first men’s basketball game for the year. The Kirkland Stake organizes some friendly games for the different wards to play once a week at the beginning of the year. I can’t remember the last time I had played basketball. Possibly only one or two games since my mission. I’m currently not busy on Thursdays, so I figured I’d dust off my basketball shoes and go play with the Juanita ward.

Before the game started I practiced a few shots and remembered how much of a struggle it is to get the ball in that darn hoop. I mostly practiced close shots, because I feel really bad when I miss those. My goal for the game was the defend well, rebound, and pass should I ever get the ball.

We were playing against the Kirkland First ward and the game did not start out well for us. They played like a team and we certainly did not. I was able to get my ward on the board with having been passed to just outside the bottom of the key, to turn around and make the shot. That brought the game to 2-11.

My plan of passing a lot didn’t work out. I’m just not good at seeing open players. What generally happened was that I would get open, receive the ball and then look around. I wouldn’t see anybody else open, and since I was open I had time enough for the shot. So I would take the shot, what can I say it’s a bad habit of mine. I missed most of the time, only hitting two or three shots like that. There was only one time that I can remember where I could have shot, but passed instead. With five seconds left in the first half I received the ball at the top of the key. I could have taken the shot, but I didn’t want to miss again. Jake Scobi was just under the hoop and signaled he wanted the ball. He probably thought he was open, but had someone covering him just behind him. So I threw the ball a little to his right, which caused him to step into the open. He grabbed the ball, and following his momentum, turned around and took the shot. Sadly it didn’t go in, and the buzzer rang. But at this point we had caught up and were in the lead 25-24.

Where I did do good in the game, was steals. I had multiple blocks or steals, where I’d gain control the ball and drive it to the other end for a layup. Thankfully I never missed a layup.

The key to the second half was to keep the Kirkland First ward away from the hoop, and to guard number one. Their number one could hit three point shots about half of the time. The rest of their team could not. We got better at guarding our zones and would force them take far shots, because they weren’t hitting them. The plan was helping us keep the lead, but unfortunately they discovered that we couldn’t hit free throw shots. That caused a lot of free throws at the end of the game. A pattern emerged of them missing a shot, us rebounding, them fouling us before we could bring the ball down, us missing the free throws, and them regaining control of the ball. It was a vicious cycle.

Thankfully we won the game. I forget the exact score, and while I didn’t like how many missed shots I had, I did like the defensive prowess I showed. Turns out my layups really helped. After the game one of the refs looked at the score sheet and informed me that I scored the most points in the game. Not bad.

Sadly I probably won’t be able to play for the rest of the season. On Saturday I was helping the Boy Scouts with their Christmas Tree pickup service activity and tore my abdominal wall. So sports are going to be out of the question for the next six weeks. O’well, I’m grateful I played when I did.

Categories: Hobbies

Metroid: Other M really is that cool

January 3, 2011 Leave a comment

I haven’t played the other games in the Metroid series because of my experience with Super Metroid. I just didn’t like it. This year Nintendo came out with Other M, and after readying all of the great reviews I decided to give it a try and received it as a gift for Christmas. One of the reasons why I didn’t get it right away is that the controls aren’t a nunchuck connected to the Wii remote ala Twilight Princess, or GoldenEye 007. The controls are just a Wiimote positioned in the classic style, making the game a side scroller. So it didn’t look Wii motion control centric to me.

I’m glad that the reviews one over my reservations. The game is awesome in every way. The graphics are the best I’ve seen on the Wii, the story is really fun and involved, and the controls are great. What’s different about the controls are that it doesn’t follow a normal side scroller. Since the beginning of time, side scrolling computer games follow the pattern of having right and left move the character, down is duck, and up is either look up or jump. That way as bad guys attack from different heights the character either shoots up, at a diagonal, or jumps and shoots horizontal. What Other M does differently is remove the need for accurate shooting from the player. The player just needs to point Samus (the protagonist) roughly in the direction of the target and when you fire the weapon Samus makes up the difference. The result is that up and down on the D-pad are now free for walking away from the screen or toward the screen. Giving the camera a lot of ways to optimally position itself, and the different rooms/hallways can be of a varying depth.

All parts are not left up to the side scrolling controls either. In a way reminiscent of Super Paper Mario, pointing the Wiimote at the screen changes the view. In Other M it takes the camera from a side scroller or third person view, to the first person point of view. You can’t move Samus in this view, but you get to do precise aiming, and make use of different weapons. If the transition between the two views wasn’t seamless this would be annoying, but it is very seamless.

So with great and unique controls, great graphics and a great story, Metroid Other M is a must have single player game for the Wii.

PS. My experience though hasn’t been very single player. Amanda and has enjoyed watching me play, to see the story progress, and she likes pointing out passageways or items I may have missed.

Categories: Entertainment