Monthly Archives: May 2009

Re. Windows FAQ (the previous article)

If you didn’t like what I said, or you think that I was nitpicking, consider this. Many PC users have been running XP since it was introduced. I know that there was some resistance at first because it looked different and stuff had been moved about, BUT everything ‘Windows’ was there. A five year active life is a long time for an operating system, long enough for users to get stuck in a rut, perhaps.

When Vista came along, it should have taken all that XP was and run ahead with it. Vista was everything that XP was and more; more security, more features, more stuff moved around, more problems. Hardware incompatibility was not the most prominent of the problems. Bulk and crippling performance topped the list. In actual fact, Vista performance is nothing like as bad as it was, what with the patches and fixes which have filtered through Windows Update, but the bulk and some of the glitches remain.

PC users will have had a further two years of XP up to the point where Windows 7 is released, and first impressions are going to count. The five points I stated are what XP users are first NOT going to see. Many are going to think ‘uh oh, Vista Mk 2’ and reel back quickly.

Windows 7 will have its big opening day very soon and access to the lot is fast, but where are the doors which will let users in? Presently, the only way in is through a small window.

Hidden Files

The last post got me thinking about hidden files and file attributes and how we can manipulate them in PowerShell.  Lets start by creating a PowerShell script.

PS> "’hello world’" > test.ps1
PS> ./test.ps1

We can see the file in a directory listing

PS> Get-ChildItem test.ps1

    Directory: C:scripts

Mode                LastWriteTime     Length Name
—-                ————-     —— —-
-a—        30/05/2009     13:57         32 test.ps1


We can view the file attributes

PS> Get-ItemProperty -Path test.ps1 -Name Attributes

PSPath       : Microsoft.PowerShell.CoreFileSystem::C:scriptstest.ps1
PSParentPath : Microsoft.PowerShell.CoreFileSystem::C:scripts
PSChildName  : test.ps1
PSDrive      : C
PSProvider   : Microsoft.PowerShell.CoreFileSystem
Attributes   : Archive

We can set the attributes so the file becomes hidden using the Fileattributes enumeration

PS> Set-ItemProperty -Path test.ps1 -Name Attributes -Value ([System.IO.FileAttributes]::Hidden)

as shown previously we have to use the force to get a listing

PS> Get-ChildItem test.ps1 -Force

    Directory: C:scripts

Mode                LastWriteTime     Length Name
—-                ————-     —— —-
—h-        30/05/2009     13:57         32 test.ps1

But we have over written the existing attributes – oops.  Need to recreate the file and try again.  This time we will add the attribute.

PS> Set-ItemProperty -Path test.ps1 -Name Attributes -Value ((Get-ItemProperty -Path test.ps1).Attributes -bxor [System.IO.FileAttributes]::Hidden)

and we now see the existing attributes are preserved

PS> Get-ChildItem test.ps1 -Force

    Directory: C:scripts

Mode                LastWriteTime     Length Name
—-                ————-     —— —-
-a-h-        30/05/2009     14:11         32 test.ps1

We can clear all the attributes or just rest to those we require

PS> Set-ItemProperty -Path test.ps1 -Name Attributes -Value ([System.IO.FileAttributes]::Normal) -Force
PS> Get-ChildItem test.ps1 -Force

    Directory: C:scripts

Mode                LastWriteTime     Length Name
—-                ————-     —— —-
—–        30/05/2009     14:11         32 test.ps1

The full range of attributes can be seen

PS> [enum]::GetNames([System.IO.FileAttributes])

Normal rules still apply so we can’t compress an encrypted file

Telerik’s Scheduler Recurrence Capabilities

For those using Telerik’s RadScheduler control, I explained about the options that the scheduler uses to recur by:  I don’t know if the latest release has changed some of these settings, but this article was up to date as of the previous 2008.3 release.  The scheduler uses a unique convention to identify recurring appointments within the scheduler control, and I give an overview of the various features.  Once you have an understanding of these features, using the scheduler control becomes easier.

For instance, one of the weird things about the control is how it keeps track of modifications to recurring appointments.  The recurrence string stores a list of excluded dates; these dates block appointments from showing on the calendar.  In addition, the API for the scheduler creates a new entry for modified instances of the recurring appointment (when changing a single instance within the scheduler).  I hope this article can help you understand the recurrence features the scheduler provides.

I also provide an overview of the control here:

Windows 7 FAQ..

Round colorful thingummybobber here:

1.. Where is the START button?

We believe that the START button was far too recognizable as a feature of XP, and so we decided to give it a new look. Also, we wanted to make it more of a challenge for support people to give a description of what you would first click on for access to the rest of Windows.

2.. Where is ALL PROGRAMS?

Having set the first challenge as per above, we thought that you might be getting into the swing of it. So, rather than present you with a cascading list of everything which is installed, you now have to look around the desktop for a clue.. pssst.. the clue is in the new ‘search’ box.

3.. Where is the CLASSIC MENU?

Our records show that nobody still alive knew about the Classic Menu. Are you a Linux spy?

4.. Where is QUICKLAUNCH?

This feature was far too neat and organized and it left too much space free on the taskbar. By pinning program icons onto the new taskbar, you will look far busier than you are even though you may only be playing Solitaire and reading/sending mail occasionally (very important if you are a corporate employee). It will also make you use the new magnifier function when looking for tiny icons interspersed between what you have open on the desktop. Have you tried it yet? Just type ‘Magnifier’ in the search box (omit all parentheses). See how easy that was?


We take all end user complaints very seriously indeed. We recognize that Windows Vi.. Vi.. Vi, the previous version, took up an extraordinary amount of disk space, and that many upgraders to the previous version could not install the operating system onto a 10gb hard drive. In fairness, it is still not possible with Windows 7 but, as a token gesture to the complainers, we have gone some way to reducing bloat by removing a few k of useful code, some of which included a mail client.

Notes: To further enhance Windows 7 slim look, we have made IE8 a removable feature. However, we do not recommend removal of this feature until it has been used to locate a download site for a competing product. You will also need a browser to locate a mail client which is Windows 7 friendly.

Also, look out for the next upcoming release of Windows, code name WUFB (Windows Users Fight Back) which will include new features including a START button, easier to use menu, and something to enable the user to send e-mail without having to look on the Internet for it.

Peace, brothers and sisters..

Multithreading: queuing work items

As we’ve seen in the last post of the series, we can use the thread pool for scheduling several “types” of asynchronous operations and to amortize the penalty we pay when we need to create extra threads. In fact, I’d say that most operations should be performed by using a thread from the thread pool.

Today we’re going to look at one of the operations we can perform on thread pool: queuing work items. Interacting with the CLR managed thread pool can be accomplished through one of the several static methods of the ThreadPool class. For queing work items, we can use one of two methods: QueueUserWorkItem or UnsafeQueueUserWorkItem.

public static bool QueueUserWorkItem(WaitCallback callBack);
public static bool QueueUserWorkItem(WaitCallback callBack,
                                                                             object state);
public static bool UnsafeQueueUserWorkItem(WaitCallback callBack,
                                                                                 object state);

According to Joe Duffy’s excellent book, you should disregard the return value because failures will always be communicated through exceptions (I did check the docs and they don’t mention what false means :),,)

The main difference between the two is that the latest does not capture the ExecutionContext when you queue the work item (which means that it won’t also be used when the callback you pass is invoked). Both methods allow you to pass a reference to some object which will get passed to the callback when its processed.

Even though QueueUserWorkItem is more “secure” than the UnsafeQueueWorkItem (due to the fact that the context is captured and flowed – since the SecurityContext is part of the ExecutionContext, this means that you cannot elevate privileges by queuing work items on the thread pool), it’s also true that QueueUserWorkItem is slower than UnsafeQueueWorkItem (due to the overhead imposed by capturing and restoring the context).

When using a thread from the pool, it’s important to understand a few points:

  • you don’t control the thread that will invoke your callback;
  • the pool has only background threads. This means that they won’t keep a process running when the main thread exits. If you need to ensure that, then you need to create a thread by hand (ie, you need to use the Thread class);
  • Don’t forget the clean up before ending your work (especially if you’ve set cultures and other stuff). Even though these might get cleaned, there are some that won’t (ex.: TLS state – which, btw, you shouldn’t be using).

Enough talk…let’s see some code:

static void Main(string[] args) {
Console.WriteLine("Main thread Id: {0}",
  var evt = new ManualResetEvent(false);
  ThreadPool.QueueUserWorkItem( state => {
       Console.WriteLine("Thread Id: {0}",
       Console.WriteLine("FInishing work");
     Console.WriteLine("Ending program");

The QueueUserWorkItem method expects a WaitCallback delegate which looks like this:

public delegate void WaitCallback(object state);

The state parameters will only contain a valid value when you use the overload which receives an object parameter. As you can see, the code is pretty similar to the one you had when we created threads “by hand”.

The most important detail of the previous code is synchronization! If we didn’t wait on the event, we wouldn’t really see much because the process would terminate before the secondary thread would have a chance to end (since pool’s threads are background threads, they don’t keep the process alive when all foreground threads have ended running).

And that’s it for today. Keep tuned for more on the thread pool.

VS 2010 color scheme patch

If you enjoy dark themes and love VS 2010, then you know you’re into trouble. The problem is that VS looses the dark background after being closed and you need to go to the options, fonts and colors and then apply the current settings (which still have the correct color) again.

The good news is that is no longer necessary. You just need to install the background patch extension from the VS gallery.

thanks for the fix guys!

Some Excellent FireFox/Firebug Tools/Addons

I’ll probably come back and update this post, but I wanted to post some excellent addons or tools that can be used with Firefox/Firebug, available here:

10 Firefox Add-Ons for Web Designers:

10 Firefox Extensions for Web Analytics:

FireAtlas, an ASP.NET AJAX utility:

FSDeveloper on the move

Soon the FSDeveloper website is going to move to a different hosting company. For more details please check this post on the forums.

Downloading .NET reflector

Not sure on how I should classify this, but I’d say that getting this error in 2009 from a page served by a company like redgate is incredible! Today I needed to download reflector, so I went to redgate’s site and chose the download option. When you do that, you’ll be redirected to a page that asks for name and email. Since I was in a hurry, I’ve just hit several keys in the keyboard and ended up introducing this:


Notice the < on the email…then, clicking the download free copy produced the following result:


fantastic, right?

Removing Hidden files

I used the OneNote 2007 Side Note utility this morning and for some reason it created a table of contents file ( .onetoc2 ) file in each of the folders in which I keep my PowerShell. Strange behaviour.  Any way there are more of them than I want to delete by hand.

Get-ChildItem doesn’t show them – they are hidden files so we need to use

Get-ChildItem -Filter "*.onetoc2" -Force –Recurse

then we can pipe that into Remove-Item

Get-ChildItem -Filter "*.onetoc2" -Force -Recurse | Remove-Item –Force

again using the Force.  All gone.

And that young Luke is how you get rid of hidden files. Pity I didn’t post this on 4th May

Technorati Tags: ,

Recent Comments