New blog for my RSS feed
March 28th, 2008
I love how the internet just let you stumble onto new and great things. Be it the latest “Funniest Home Video” on youtube or another great blog writer. Just today I was going through my rss feeds and Max Pool had a quick little post on a new blogger he has been reading.
Now Max’s article isn’t much more than “I like his posts here are a few of my favs“. Short simple and piqued my interest.
So I went over to Jurgan Appelo’s blog and took a look at the arctiles and low and behold I think I agree with Max. Jurgan you have some great posts and I am going to add you to my feeds that I use to help better myself as a developer and aspiring Project Manager.
I could make a few posts on what I have taken away from each of the articles I have read on his blog but I don’t really have the time so here is a recap of the posts I read:
- Make It Simple vs Do It Simple
- Complex versus Complicated
- MoSCow Priorities
- The Single Above-Average Programmer
Plus I think if I read these posts again in a few months even I would get something different from them.
Thanks Max and Jurgen
Thread safe EventHandling in C#
March 25th, 2008
I ran into a little issue with trying to update a UI from a working thread. I was working on refactoring some code which I took from .Net 1.1 and upgraded it to .Net 2.0 as well as refactoring some of my earlier work. Code that I now look at at slap myself trying to figure out why I had put all the business logic directly into the UI class. Dumb me. But that is all part of the learning process and I don’t know anyone that writes code they are satisfied with when looking back on it a few days, months or years down the road.
Alright, enough of a side track back to the threading issue. Basically in the .Net 1.1 land you had to declare a a delegate and then create a instance of that delegate and then use that instance in your thread to do the actual updating. It can get quite messy. At least from my perspective. Here is a small example:
public class UI
{
public delegate void UpdateProgressBarDelegate(int percent);
public UpdateProgressBarDelegate updateProgress;
public UI()
{
updateProgress = new UpdateProgressBarDelegate(incrementProgressbar);
}
}
Now in a function somewhere on the working thread you would have this:
private class doingTheUpdate(int percent)
{
mainUI = updateProgress.Invoke(new object() { percent });
}
With .Net 2.0 it gets a bit simplified and you can use the EventHandler class to create an event and you don’t have to declare the delegate and then create an instance. Below is an example:
public class MyUI
{
public event EventHandler UpdateProgressEvent;
public void InvokeUpdateEvent(int percent)
{
InvokeUpdateEvent(UpdateProgressEvent, percent)
}
[MethodImpl(MethodImplOptions.NoInlining)]
private void InvokeUpdateEvent(EventHandler handler, int percent)
{
if( handler != null )
{
MyEventArgs e = new MyEventArgs(percent);
handler.BeginInvoke(this, e, null, null);
}
}
}
Now doesn’t that seem a bit more concise. I admit I am doing some other things there to help make this thread safe and I got most of this from Dave Brook’s at Aliens ate my GUI. So I will try to summarize what it is doing.
First where it looks like I am declaring the method InvokeUpdateEvent twice, once as public and once as private, I am. The reason this is done is because you can get a race condition if you just check for null and then call the event. A way to fix this potential race conditions Dave explains it very well so I won’t try.
“One counter measure is to make a copy of the delegate. Delegates are immutable so by copying it to a temporary variable you keep a copy of the original state of the delegate, irrespective of any thread context switches. Making any change to the state of the delegate creates a new one on the heap and updates the reference to which the delegate point.”
As well on the private InvokeUpdateEvent declaration there is a attribute added. This is added because the JIT compiler might optimize the code above and basically get you back to the state before where the race condition can occur. So the [MethodImpl(MethodImplOptions.NoInlining)] attribute is used to tell the JIT not to optimize this function.
The only other item in there is MyEventArgs class. This would just be a class that inherits from the EventArgs class and adds any info that needs to be sent with the event. In this example it was just the percent to update a progressbar.
Hope this helps. I know it helped me.
Edit:
Well I have jumped the gun a bit on this one and it looks like I needed to add one more thing to this to make it work on threads. when I call the event in the last function I still will need a BeginInvoke to make sure that it is run on the correct thread or else I get a cross threaded exception thrown. I have edited the code above to reflect this.
Also if you have any suggestions to improve this please post a comment. I am not perfect even though I tell myself I am.
GDoc’s as blogging tool
March 13th, 2008
This morning while trolling through my RSS feeds I found this dandy article on how Google has added a great feature to their Google Docs arsenal. On the Publish tab you can now setup up your blog settings and have a one click publish directly from Google docs.Right now I am writing this blog post inside Google Docs and since I went through the quick setup I was able to post this document directly to my blog. I have been looking for a tool to help kick start my blogging and it seems I have found it. I have been using the Docs and Spreadsheets features (haven’t found a need for Presentations yet) for a while now and this is a great addition. Not only do I have a backup of all the wonderful articles I create but I have a one stop shop for all my docs, blog articles or not.
Previously I was using the demo version of BlogJet. BlogJet is a great tool but I couldn’t justify spending £29.95 (or about $60 CDN) on a blogging tool even with all its features. I am more into the free solutions for blogging since it is not an income generator but a tool for me to place my random thoughts and interests online to share and to archive.
Using Google Docs as my blogging tool will be good but there are a bunch of feature that I will be missing. The first will be the selecting a category for the article. It seems that Google has allowed for the Docs tagging system as a way to map to the categories on your blog.
“To automatically categorize your blog posts, just tag your documents with a category name you already use on your blog site.”
This will limit you on categorizing you posts to ones already generated on the blog. So I guess you better have all your categories setup before hand. I am not sure if I add the category after the article is publish, if it will automatically be placed in there or if I would have to republish the article from Google Docs or manually place the article in the category. I guess some testing is in order.
Another feature that I would like to see is for Google to add the ability to actually tag the articles as well. I am using a self hosted Wordpress install as my blog engine and with it I can tag each article with key words that help search the site to find similar article. It would be great if on the publish tab I could add a bunch of tags and have them posted with my article.
Probably not the last feature but the last feature for this article, I would like to see a way to postpone publishing. Some sort of method to be able to have a few articles in the queue and have them posted when I specify. This would be something like the feature in PixelPost, which I use for my photoblog. I can upload a bunch of photo’s to and for each one specify the date and time on when to publish them. For this though I guess on the publish tab there would be a “publish now” button and a “publish later” button that has a date and time entry field associated with it. When the date and time come up the article gets automatically published.
I will continue to use Google Docs for now and see where it takes me and how useful it is. This might not be powerful enough for everyone but I think it should suffice for me.
Update:
Well it looks like the Title is not working for Wordpress, as I had to manually add the title on this entry.
As well there categorizing did not work either. I have my docs in a folder called “blog” and subfolders for each category and it posted the entry under uncategorized (the default category).
As an FYI folders are Google’s tags.