BizArk Feature Spotlight – Splash Screen

by Brian Brewder August 30, 2009 11:47

The splash screen is a common feature in many desktop applications. A splash screen is used to provide feedback to the user as the application initializes. If your application does not have a long initialization process, it does not need a splash screen, and should not have one (the splash screen can become annoying after a while, especially if it is not necessary).

If you are in need of a splash screen, the BizArk framework provides the capability to show the splash screen on a thread while you initialize your application in Main (the starting point in Windows applications). You do not need to worry about any of the threading issues, BizArk takes care of all that for you. If you are interested in learning how to display a form on a separate thread, check out the source code in SplashScreen.cs, BizArkWinForms project.

The BizArk SplashScreen class provides the following capabilities:

  • Displays a custom splash screen on a separate thread to allow for initialization on the main thread.
  • Provides a mechanism to send progress to the splash screen.
  • Can fade in and out to give a more finished, polished look.
  • Set a minimum time to show the splash screen.

The splash screen is easy to use. Just create your splash screen as a standard Form. In your programs Main method (usually in Program.cs), create a new instance of Redwerb.BizArk.WinForms.SplashScreen and send in the type for your custom splash screen. When you are ready to show your splash screen call ShowSplash and when you are done with it call HideSplash.

If you want to send status updates to the splash screen, your form will need to implement the ISplashScreen interface. The BizArk SplashScreen object will route the status to the correct thread so that you don’t need to worry about cross threading issues (problematic with WinForms).

Below is an example of calling the splash screen from the RedwerbEntry project (a test project available in the BizArk Framework download):

    SplashScreen splash = new SplashScreen(typeof(Splash));
splash.FadeInTime = 500;
splash.FadeOutTime = 500;
splash.MinShowTime = 3000;
splash.ShowSplash();
//todo: remove sleep (used for testing purposes).
splash.Status = "Sleeping";
System.Threading.Thread.Sleep(cmdLine.RunTime);
//todo: initialize the application including creating an instance of the main form.
//var frm = new MyForm();
//var frm.Initialize(); // or whatever you need to do to prepare the form before display.
splash.Status = "Hiding";
splash.HideSplash(true);
//Application.Run(frm);

BizArk is available for download on the CodePlex website, http://bizark.codeplex.com.

BizArk Feature Spotlight – String Templates

by Brian Brewder August 06, 2009 22:45

I’ve never liked that String.Format requires you to provide indexed arguments. I’m a bit anal and like my arguments to increase from left to right so that if I add a new argument to the beginning of the string I end up renumbering all the subsequent arguments (hey DevEx, perhaps you can add this to Refactor!?). 

This isn’t too big of a deal for small strings, but it can make it difficult to work with large strings with a lot of arguments, especially when the text and arguments change frequently. To get around this, I often times resort to using named parameters and String.Replace (see the example below).

var str = "{greeting} {name}!";
str = str.Replace("{greeting}", "Hello");
str = str.Replace("{name}", "World");
Debug.WriteLine(str);

Surprisingly performance doesn’t seem to be a major problem with this approach. Iterating 1,000,000 times using string.Format("Hello {0}: {1,2}", "World", i) took ~650 milliseconds vs string.Replace which took about ~900 milliseconds. This might add up to a significant difference in extreme situations, but in most cases it is negligible.

However one major drawback to string.Replace is that you lose the ability to specify formatting in the string which can be very handy, especially when you are dealing with regional formatting issues.

So in order to help with this, I added the StringTemplate class to BizArk which allows you to create a format string that combines the best of both worlds, named arguments along with specifying formatting in the string (see example below).

var template = new StringTemplate("{greeting} {name} on {date:dddd, MMMM dd, yyyy}!");
template["greeting"] = "Hello";
template["name"] = "World";
template["date"] = DateTime.Now;
Debug.WriteLine(template.ToString());

This will print out “Hello World on Thursday, August 06, 2009!”.

StringTemplate actually uses String.Format to format the string so any formatting that you can use in a String.Format argument you can use in a StringTemplate argument. The names are not case sensitive, but they must conform to the same standard as identifiers in C# (upper/lower case letters, numbers, and underscore).

I also created a generic version of StringTemplate. The generic version exposes a property that you can use to set the parameters. If the type has a default constructor, StringTemplate<T> will instantiate it for you (you can also set it if you prefer).  The name of the arguments should match with the name of the properties. It uses the TypeDescriptor class to get the properties, so you can implement ICustomTypeDescriptor if you want. This should make it fairly easy and painless to do mail-merge type functionality.

BizArk is available for download on the CodePlex website, http://bizark.codeplex.com.

The FizzBuzz Interview Test

by Brian Brewder August 02, 2009 12:20

Over the last week I have been interviewing people for a Flash Developer job at my company. This is my first time hiring and it has been an interesting experience.

The first thing that struck me as odd are the number of applicants that didn't come even close to meeting the minimum requirements for the position. The ad said the minimum requirements were 4 years web development experience with 2 years Flash development experience including animation using ActionScript. The ad described the position as a non-design position that will include other development activities as well. Out of 2 dozen or so applicants, only 3 were qualified enough to bother interviewing.

Now it should be said that I'm not a Flash developer, in fact, I've never worked with Flash at all so I was unsure of how to determine if a developer had the experience and ability to do what we need. A portfolio helps, but is not necessarily sufficient to determine coding proficiency.

I am an avid reader of Coding Horror, Jeff Atwoods blog. One of the things that he suggests is administering the FizzBuzz test (the idea seems to have originated from Imran on Tech). I modified the FizzBuzz test a little from the original article, ours went something like this:

Loop 15 times, every 3rd time write Fizz, every 5th time write Buzz, and the 15th time write FizzBuzz.

We also asked the candidate to develop it in the Flash IDE instead of on paper.

When I gave this test to the first candidate, I wasn’t sure what it would prove. It’s such a trivial test that it doesn’t seem like it would prove anything. However, when I watched the candidate perform the test, I learned a number of things about them.

  • Familiarity with the development environment
  • Understanding of basic computer math concepts
  • Confidence in their coding ability
  • Interest and willingness in solving problems
  • Ability to write clean code

I’m a little hesitant to give complex coding problems during an interview. This isn’t the same type of stress that occurs naturally on the job so I don’t believe that it shows how well they work under pressure. However, since FizzBuzz is so trivial, I didn’t feel bad at all about asking the candidate to do the test on our huge conference room monitor in front of me and my co-interviewer.

If you are interviewing a candidate, I would highly recommend giving this test.

Powered by BlogEngine.NET 1.6.0.0

About the author

I've been a software developer since 1999 and have been working with .Net since 2002. I love creating software, playing with productivity tools, and improving the process of software development. I hope you enjoy my blog. Please feel free to leave comments or contact me, I would love to hear from you.