Fun

Book Review: MCTS exam 70-505 Windows Forms Application Development Training Kit

July 18, 2010 Book Reviews, Certification, Fun 6 comments

Oh! Yet another training kit on Microsoft exam. This time it is Windows Forms Application Development (exam 505).
It was extremely boring to read this book.

Book talks on different Windows Forms related stuff. From the beginning it tries to teach me how to create simple forms app and add controls to it, but hey with my experience developing applications it is too boring. In advanced WinForms controls it talks on ListBox, TreeView, CheckBoxes and so on :) After so complex things it leads me to ADO.NET and how to work with connection Strings and how to even read data from DataReader. In advanced topics on Windows Forms Development it talks on how to create MDI application. OMG, i knew how to do them on my 3rd year in university. In asynchronous operations it talks on how I can use BackgroundWorker and even what is Thread and how to synchronize two of them. Maybe the most interested chapter was Deployment, at least because I never really used it either at work or in university.

But you know what is the most funny about all of this? – Possibility that I will not pass this exam. Why? – Because these entry ms exams are kind of exams for con. It require simple knowing of names of classes and functions. But on other hand I understand, that they couldn’t make it different.

You just need to read this kit to pass this exam, almost no way to do it different.
I understand that if you have no experience working with Windows Forms book could bring lot of value for you. For example, do you know how to create not rectangular button or how to print documents programmatically.

Fact that I read this book means only one – which I’m going to schedule exam for next Friday and spend my evenings trying tests from book, and maybe MeasureUp. Also researching over internet how to prepare myself fot it.

So, wish me good luck on passing this exam.


6 comments


Firefox 3.6.6 update dialog :)

July 16, 2010 Fun 2 comments

Today Firefox asked me for update, of course I approved.

When it started downloading updates very quickly I got this picture:

Readers, do you see anything wrong with it? :)

I never thought that guys from Firefox could do such fun and stupid bug, but this proves that we all are human, still not ideal robots.


2 comments


AppDomain.UnhandledException and Application.ThreadException events

May 19, 2010 .NET, Concurrency, Fun No comments

Today I was playing with exception handling and threading in .NET. It was really fun.

Do you know guys that like to have everything in global try-catch block? I have two news for them.

Bad one

Exception will not be caught in try-catch block if it was thrown in another thread. Those guys also could think that Application.ThreadException could help them to catch those.

        [STAThread]
        static
void
Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;
         
            Application.Run(new Form1());
        }

        static
void
Application_ThreadException(object
sender, System.Threading.ThreadExceptionEventArgs
e)
        {
            MessageBox.Show(“This is
something that I would not recommend you to have in your application.”
);
        }

But indeed this event fires only if exception has been thrown as result of Windows message or any other code that runs in same thread were your WinForms application lives. I tried to use two timers to verify that.
System.Windows.Forms.Timer – which ensures that code you have in your tick method runs in the same thread as your application. In this case I got message box.
System.Threading.Timer – which runs in separate thread, so my app just crashed.

But if those guys are writing all code in Form1.cs file… then maybe it worth for them to have handling of Application.ThreadException event :)

“Good” one

There is event which will be fired when exception is thrown from any code/thread withing your application domain. It is AppDomain.UnhandledException and it occurs when exception is not caught.

Lets take a look on code snippet that shows this:

        [STAThread]
        static
void
Main()
        {
            AppDomain currentDomain =
AppDomain.CurrentDomain;
            currentDomain.UnhandledException +=
currentDomain_UnhandledException;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
         
            Application.Run(new Form1());
        }

        static
void
currentDomain_UnhandledException(object
sender, UnhandledExceptionEventArgs e)
        {
            MessageBox.Show(“This is
shown when ANY thread is thrown in ANY point of your Domain.”
);
        }

To test this I created Threading.Timer and fired it every 2 seconds and throwing exception on each tick, I put breakpoint into event. I got everything expected and application after that failed.

But one of our smart guys could guess to put Thread.Sleep(1000000); into handler code like below:

        static void currentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
        {
            Thread.Sleep(1000000); //
Try to guess what will happen

        }

Everyone is happy. Exception is thrown each 2 seconds or less and UI continue to respond. I hope you already see what is wrong with all of this.

This screenshot talks for itself:

 (My app already ate 705 threads and still eats…)

And as you know process could have up to 1024 threads. My process is not exclusion and it also crashed after reached that number.

Ok, looks like guys should change their mind.

Hope it was a bit fun.


No comments