Category Archives: ASP.NET C# and Visual Studio

ASP.NET 4.5 and Visual Studio 2012 Essential Skills book available

My new book for ASP.NET 4.5 and Visual Studio 2012 is now available from Amazon and other book retailers.

I’m currently working on the video version of the course, and hope to be able to offer it soon.

You can buy the new book from Amazon by clicking here.

Expert Skills video course now available

The Expert Skills video course is now finished and available here.

You can watch some sample videos, and the entire Essential Skills video course absolutely free here.  There are now over 140 free video lessons – over 14 hours of free tutorials.

 

Expert Skills update

The Expert Skills book has now been officially published and is being listed by Amazon. It may be a few days before Amazon has the book in stock, but it is available for pre-order in the UK.

Expert Skills update

The Expert Skills course is currently in the final stages of proofreading.

After proofreading, the book will need to be indexed before a test print run can go ahead. Assuming there are no problems with the test print, it will then be ready to go on sale.

Everything is on schedule for a June release.

ASP.NET and security

In the course of writing the Expert Skills course, I’ve recently written lessons about SQL injection and cross-site scripting attacks.  What struck me when writing these lessons is just how secure ASP.NET is.

It’s extremely difficult to make an ASP.NET web application vulnerable to cross-site scripting attacks. A developer would have to manually disable ASP.NET’s security features before an attack would even be remotely possible. Even then, most of ASP.NET’s controls will automatically filter out any attempt at cross-site scripting.

SQL injection attacks present a slightly greater risk, as it’s still possible to create a vulnerable application if you send SQL code directly to the database. Standard LINQ, however, provides complete immunity to SQL injection.

It really is impressive how ASP.NET’s protects your applications from the most dangerous forms of attack, even when using its most basic features.

Expert Skills update

Another update has just been made to the Expert Skills course outline.

The editing and indexing process will soon begin, changing the book from a first draft into a polished and complete course.

Expert Skills update

The Expert Skills course is progressing well and the course outline has been updated again.

There’s now an entire session dedicated to crpytography and threading, as there was just too much to cover for them to be grouped with the other advanced .NET Framework features.

How is C# threading like peeling potatoes?

I’ve been working on the Threading lessons for the C#, ASP.NET and Visual Studio Expert Skills book, and an interesting analogy struck me.

I have a sack of potatoes that need to be peeled as quickly as possible. I also have two chefs, Jo and Bill, who are in kitchens on opposite sides of a building.

In the first scenario, I deliver the potatoes to Jo and Bill one at a time, running backwards and forwards from the sack. It takes so long for me to carry each potato to the chefs that it would actually be faster to peel them myself.

This is the same when working with C# threads. Using two threads to accomplish a lot of small tasks is actually slower than doing all of the tasks using a single thread because of the overhead that’s added by managing the threads.

This code uses the “single potato” approach to check prime numbers up to MaximumValue:

while (CurrentValue < MaximumValue)
{
    if (!FirstThread.IsAlive)
    {
        FirstThread = CreateThread();
        FirstThread.Start(CurrentValue);
        CurrentValue++;
    }
    if (!SecondThread.IsAlive)
    {
        SecondThread = CreateThread();
        SecondThread.Start(CurrentValue);
        CurrentValue++;
    }
    Thread.Sleep(1000);
}

This code gives each prime number to the two threads individually. The prime numbers are the ‘potatoes’ in this instance. Because there’s so much overhead starting and stopping the threads, this code is actually much slower than it would be if it didn’t use any threading code at all!

So what’s the solution to the potato problem?  Well of course, it doesn’t make any sense to carry the potatoes one at a time. It would be much more logical to give half of the potatoes to Bill and the other half to Jo. That way they can do their jobs and there’s no time wasted running backwards and forward from the potato sack.

In C# terms, that means our solution is to divide up the prime numbers between our two threads and have each thread process them all in one go instead of starting a new thread for each number.

Here’s how the code looks with the prime numbers divided up between the two threads.

Thread Thread1 =
new Thread(new ParameterizedThreadStart(CalculatePrimes));
Thread1.Start(new int[]{2,StartingPointForThread2-1});
Thread Thread2 =
new Thread(new ParameterizedThreadStart(CalculatePrimes));
Thread2.Start(new int[] { StartingPointForThread2, MaximumValue });

while (Thread1.IsAlive || Thread2.IsAlive)
{
    Thread.Sleep(1000);
}

In this code, the two threads only start once and don’t need to restart for each prime number. This implementation is much faster than working with a single thread (or peeling all of the potatoes yourself!).

There’s a lot more about threading in the Expert Skills book, including using the ThreadPool class to manage threads more easily. ‘Learn ASP.NET 4.0, C# and Visual Studio Expert Skills with The Smart Method’ will be available for purchase around June 2012.

Expert Skills Session 1 Finished

Continuing on with Expert Skills, I’ve now finished Session 1 and sent out a proof to my proofreaders. If you’re on of them, you should have it by now!

Session 1’s taken longer than I expected, but that’s mostly down to the amount of time I’ve spent working on the sample files for the new course. Being Expert Skills, the sample files need to make use of far more complex features than those used in Essential Skills.

So far I think the Expert Skills course does a great job of applying to real-world scenarios. Once it’s finished I’m confident that the two books will be the absolute best way to learn ASP.NET, C# and Visual Studio.

Getting started with Expert Skills

Now that the Excel 2010 Expert Skills video course is complete, I have begun work on the ASP.NET 4.0, C# and Visual Studio 2010 Expert Skills book.

If you’re a proofreader, you can expect to start receiving PDF versions of the first drafts in the coming weeks.

I have also revised the course outline, adding an entirely new session on compiler directives and advanced debugging techniques. The outline is likely to continue to change as I receive more suggestions from our readers.

If you have a suggestion for something you’d like to see in the Expert Skills course, get in touch and let me know!