My Doc's Got No Nodes

Looking for a punchline since 2002

This is another post about a problem that I could have solved much quicker if I’d found the right blog posts. It’s common enough that .net 4.5 will include a new Task.Run method that saves you from this mistake.

The symptom was that a task that was supposed to run in the background while the UI thread did some other work wasn’t starting – it was scheduled but didn’t run.

The reason was that the supposed background task was started from some code that was (further back in the call stack) inside a task that had been scheduled on the UI thread, using a common pattern of specifying the scheduler.

If you’re already inside a task, creating or starting a new task without specifying a scheduler picks up the scheduler of the parent task, not the default scheduler.

        public void ButtonClicked()
        {
            var onUiThread = TaskScheduler.FromCurrentSynchronizationContext();

            var task = new Task(() => DoSomethingInTheBackground());

            task.ContinueWith(t => DoSomethingUIRelated(), onUiThread);

            task.Start();
        }

        public void DoSomethingUIRelated()
        {
            var offUiTask = Task.Factory.StartNew(() => SomethingElseForTheBackground());

            ///
            /// Do some UI-thread stuff
            ///

            offUiTask.Wait();
        }

So, on the UI thread, a task is created which calls DoSomethingInBackground. When that is finished, DoSomethingUIRelated is called – on the UI thread by specifying the scheduler onUiThread.

But when the task to call SomethingElseForTheBackground is created, it inherits the UI thread scheduler, and because the UI thread starts a Wait for it, it never gets a chance to run.

The solution is to specify TaskScheduler.Default for offUiTask, or to use the new Task.Run method when .net 4.5 comes along.

This is another one of those posts to give the answer to a problem that I couldn’t find with Google.

I was implementing a method call by:

  • a BindGetMember on a dynamic meta object, returning an expression which returned a new dynamic meta object provider for the method.
  • a BindInvoke on the dynamic meta object for the method.

Because the dynamic meta object provider for the method didn’t pass itself (i.e. this) into the value parameter for the dynamic meta object representing the method, the binding restrictions created didn’t match the expected type and so they weren’t cached by the CLR.

Instead, it just looped round and round (in System.Dynamic.UpdateDelegates.UpdateAndExecute2) trying to cache the new rule. The fix was to make sure that the DynamicMetaObject has a Value of the original IDynamicMetaObjectProvider instance.

Hope that helps someone else.

If you’re running a .net 4 app built for the .net Client Profile, then you might get the following error when trying to run it on mono:

> WARNING: The runtime version supported by this application is unavailable.     
> Using default runtime: v2.0.50727

To work-around this problem, you can either remove the line

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>

From the app.config file (or yourprogram.exe.config), or add the switch

--runtime=v4.0.30319

To the mono command-line.

I hit a problem with doing a preseeded Ubuntu installation, where the partitioning wouldn’t continue without a confirmation.

I found lots of discussions about how to work round the problem with the "write the changes to disks and configure lvm" message, but I could have fixed the problems with a lot less trial and error had I known this earlier:

  1. Edit the “append” line of the pxelinux.cfg/default file to include DEBCONF_DEBUG=5
  2. Press Alt-F4 at the point where the automated install hangs to find out what parameter was missing to cause the user prompt.

Previous article here

Well now that T-mobile have pushed out the OTA update for the G2 Touch (HTC Hero), I’ve got Android 2.1 and can connect the phone to 2 Google accounts without a problem.

The only minor problem was that the widget for the Gmail inboxes looked identical and didn’t display unread counts.

These two problems were fixed with this great widget by Alexander Blom, there’s a barcode to jump to the marketplace entry on his web page.

Previous 5 of 8 Next