January 2007 Entries

500

I've averaged 13.5 posts per month over the last 37 months to arrive at today's post #500.I'm not sure if I'll make another 500 posts, but I have pages of notes for posts covering ASP.NET, AJAX, Windows Workflow, WCSF, and more. I also have enough material for at least 15 more "What's Wrong with This Code" posts, which several people have told me are fun and educational. One day, I might even finish my "Design Patterns - A Love Story" post. Then again, maybe that story should be purged from the Internet forever.  Thanks for reading!

More on Managing Windows Workflow Events in ASP.NET

In the last post I pointed out problems you can experience trying to handle workflow events in an ASP.NET page. Before we get to a working solution, let's take a look at another pitfall. We know the default WF scheduling service will select a thread from the CLR thread pool to execute workflows asynchronously. Generally speaking, this isn't a good approach for server side applications because we can tie up too many threads. Instead, we use the ManualWorkflowSchedulerService. The manual scheduler lets us run workflows on the same thread that is processing the HTTP request. We just need to call...

Managing Windows Workflow Events on a Web Server

Once you have the WorkflowRuntime up and running in an ASP.NET application or web service, you'll want handle key life cycle events like WorkflowTerminated and WorkflowCompleted. I want to warn you about some common pitfalls I've seen. There are two subtle but extremely dangerous problems in the following code. protected void Page_Load(object sender, EventArgs e) {     // get a reference to our WorkflowRuntime singleton     WorkflowRuntime runtime = ApplicationInstance.WorkflowRuntime;          // wire up an event handler     runtime.WorkflowCompleted +=         new EventHandler<WorkflowCompletedEventArgs>               (runtime_WorkflowCompleted);     // create and start a new workflow     WorkflowInstance workflow;     workflow = runtime.CreateWorkflow(typeof(SomeWorkflow));     workflow.Start();     // ask the manual scheduling service to execute the     // workflow on this very thread     ManualWorkflowSchedulerService scheduler;     scheduler...

TreeViews and Usability

One of the commercial applications I've worked on over the last few years has received consistent feedback from uses who dislike tree view controls. Many of these users are working with terminal emulators on a daily basis, so I first suspected that switching to a GUI came as a shock. I did some research on tree controls and usability, but didn't uncover much information. Actually, many articles I found herald the tree view as the ideal solution for categorizing and drilling into large amounts of hierarchical information. Only Alan Cooper's book "About Face" turned up a caveat: "Programmers tend to...

Some JavaScript Links To Chew On

I've flagged a few links to noteworthy JavaScript posts over the last month. Yahoo! Video: Advanced JavaScript Part I, Part II, Part III. A lecture by Douglas Crockford. IEBlog: Jscript Inefficiencies Part I, Part II, Part III. Rick Strahl: "FireBug 1.0 Beta Rocks". FireBug is a JavaScript debugger with some remarkable features. Rick again: "HREF links and javascript : Navigation". Jason Diamond: "Not Delegates". Jim Ley: "JavaScript Closures". Sergio Pereira: Quick Guide To Somewhat Advanced JavaScript. Pathfinder: JsUnit – Agile AJAX Development Mike West: Scope In JavaScript

You Can't Touch My Windows Experience Index

Leave it to Microsoft to quantify everything. The experience used to be emotional. There was the gentle purr of a power supply fan with the scent of plastics in the air. The caress of a firm, rubberized nipple would make pixels dance in front of my eyes. Those days are over. My Windows Experience is now a cold, calculated number. Top that! What's that you say? A low score is bad? Oh. Well, this desktop was a top of the line computer… … back in the year 2000.

Managing the WorkflowRuntime In ASP.NET

If you want to use Windows Workflow in ASP.NET, you'll need create and maintain a WorkflowRuntime instance. What's the easiest approach to use? The easiest approach (not necessarily the best), is to use global.asax. <%@ Application Language="C#" %> <%@ Import Namespace="System.Workflow.Runtime" %> <script runat="server">              void Application_Start(object sender, EventArgs e)     {         InitializeWorkflowRuntime();     }          void Application_End(object sender, EventArgs e)     {         if (_workflowRuntime != null)         {             _workflowRuntime.Dispose();         }     }           void InitializeWorkflowRuntime()     {         _workflowRuntime = new WorkflowRuntime();                  // ... additional configuration ...              }          public WorkflowRuntime WorkflowRuntime     {         get { return _workflowRuntime; }     }              private WorkflowRuntime _workflowRuntime;        </script> This approach gives us a WorkflowRuntime we can reach from any page. Remember, in an ASP.NET Web Site project, the runtime code-generates a strongly-typed ApplicationInstance property from global.asax for each...

What's Wrong With This Code (#10)

This time, Joe Developer thinks he found a bug in the .NET framework. Joe read that the volatile modifier is "usually used for a field that is accessed by multiple threads without using the lock Statement". Joe wants to try this out, and writes the following class. class Worker {     public void Start()     {         queue = new Queue<string>();         Thread[] threads = new Thread[maxThreads];         for (int i = 0; i < threads.Length; i++)             threads[i] = new Thread(PopulateQueue);         Array.ForEach(threads, delegate(Thread t) { t.Start(); });         Array.ForEach(threads, delegate(Thread t) { t.Join(); });                  Debug.Assert(queue.Count == maxThreads * maxIterations);     }     void PopulateQueue()     {         for (int i = 0; i < maxIterations; i++)         {             queue.Enqueue("foo");         }     }     volatile Queue<string> queue;     const int maxThreads = 5;     const int maxIterations =...

JavaScript and Threading

Someone asked me if the "asynchronous" in AJAX means we should be worried about thread safety and global variables in client-side script. This is an interesting question to ponder. A search of the ECMAScript language specification returns zero hits for the word "thread". JavaScript, like C++, appears to leave threads as an implementation detail. There are no keywords or intrinsic ECMAScript objects available to manage threads, or to provide for thread synchronization. I find it strange that there are articles like "Implementing Mutual Exclusion For AJAX" claiming to control threads. Some of these articles assert that integer assignment in JavaScript is an...

A WPF Wonderland

A couple months ago, I shared a ride to the Dallas airport with my friend Walt Ritscher. I remember Walt was excited about WPF and WPF/E - so excited it seems he now has a blog dedicated to the topic: WPF Wonderland. Walt added some west coast flair to my WPF/E Game Of Life code and hosted the sample. You can give it a whirl if you have the December 2006 WPF/E CTP installed.

AJAX UpdatePanels and ContentPlaceHolders

I've seen the following model popup frequently: <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">     <Items>         <asp:MenuItem             NavigateUrl="~/Default.aspx" Text="Default.aspx" />         <asp:MenuItem             NavigateUrl="~/Default2.aspx" Text="Default2.aspx"  />     </Items> </asp:Menu> <asp:UpdatePanel ID="UpdatePanel1" runat="server">     <ContentTemplate>         <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"/>     </ContentTemplate> </asp:UpdatePanel> This is an ASP.NET MasterPage with a content placeholder wrapped inside an UpdatePanel. A menu control provides links to default.aspx and default2.aspx - both content pages that use this master page. The misconception is that the update panel will magically reload only the area inside the ContentPlaceHolder control when the user clicks on a navigation link in the menu. This example uses a menu, but we could substitute any type of control that generates hyperlinks to a new page....

A Message For You

Some might say it's a day late, but nevertheless, it is a message. And it's for you. Of course, you'll have to figure out what the message is by reading the source code. This year's code isn't quite as ugly as last year's code, but if you can figure this one out without a compiler - three cheers! If you do figure it out, you might still want to run the code as a console application to see the full effect... using System; using System.Collections; class _2007_ {     static void Main()     {         int x, y; x = y = 0;         Console.SetWindowSize(84, 7);         do         {             foreach (string i in Order)             {                 foreach (int...

Sidebar Gadget Article

A new year deserves a new OdeToCode article: "Developing Gadgets for the Windows Vista Sidebar".Feedback is always appreciated.

How Did Life With WPF/E Turn Out?

A couple people asked me how my WPF/E port of Life turned out. Answer: it works pretty well. Here is the source code if you want to look. I built the project with an .aspx page, although I don't use any server side logic and the page could easily be plain HTML. The XAML is not fancy Expression built XAML. In fact, the board is mostly built inside script. There is just enough XAML to bootstrap the board. <Canvas       xmlns="http://schemas.microsoft.com/client/2007"       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"       Height = "300"       Width = "300"       x:Name="gameBoard"       Loaded="javascript: gameBoardLoaded"> <Canvas> I'm looking forward to future releases.

Scott Allen
Posts - 869
Comments - 4493
Stories - 14