this.GetCmp<> and X.GetCmp<> null reference exception when used in a different thread

  1. #1

    this.GetCmp<> and X.GetCmp<> null reference exception when used in a different thread

    Hi Guys,

    I've got an MVC application where I'm attempting to apply your server-side progress bar example. However, instead of using ThreadPool I'm using Tasks.

    My Long Action is being run in a Task, which has a ContinueWith call to present the result of the long action. e.g.

    var t = new Task<int>(() => Validation<int>(userId));
    t.ContinueWith(task => Result(task.Result));
    The Long Action saves its progress to the database, and my Refresh method used by my task manager picks that up and refreshes the progress bar great.
    However, my Result method which runs in the ContinueWith call can't seem to use the X.GetCmp<> method. Whenever I call it I get a NullReferenceException
    "An exception of type 'System.NullReferenceException' occurred in Ext.Net.dll but was not handled in user code

    Additional information: Object reference not set to an instance of an object."
    Is it simply not possible to use GetCmp in a different thread? I don't need to get any values, I just need to change some values/settings.

  2. #2
    Just whipped up a complete example showing the error. Task should take 5 seconds and then it should change the label from "not finished" to "FINISHED"

    <%@ Page Language="C#" %>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
            new WebApplication4.ViewModels.TestWindow().Render(true);
    <!DOCTYPE html>
    <html xmlns="">
    <head runat="server">
        <ext:ResourceManager runat="server" />
    using Ext.Net;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    namespace WebApplication4.ViewModels
        public class TestWindow : Window
            public TestWindow()
                ID = "TestWindow";
                Title = "Test Window";
                Width = 800;
                Height = 600;
                Border = false;
                CloseAction = CloseAction.Hide;
                Stateful = true;
                Items.Add(new Label()
                    ID = "testLabel",
                    Text = "not finished"
                var valBtn = new Button()
                    Text = "Validate",
                    ID = "ValidateBtn",
                    Icon = Icon.Wand,
                    IconAlign = IconAlign.Right,
                    Scale = ButtonScale.Large
                valBtn.DirectEvents.Click.Url = "ExtNet/PresentResult/";
    using System.Web.Mvc;
    using Ext.Net;
    using Ext.Net.MVC;
    using WebApplication4.Models;
    using System.Threading;
    using System.Threading.Tasks;
    namespace WebApplication4.Controllers
        public class ExtNetController : Controller
            public ActionResult PresentResult()
                var t = new Task<string>(() => Validation());
                t.ContinueWith(task => Result(task.Result));
                return this.Direct();
            private string Validation()
                return "FINISHED";
            private ActionResult Result(string text)
                var label = X.GetCmp<Label>("testLabel"); // Null Exception here
                label.Text = text;
                return this.Direct();

Similar Threads

  1. [CLOSED] App vrs getCmp
    By Z in forum 3.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 10, 2015, 9:16 PM
  2. [CLOSED] messagebox throwing null reference exception
    By sharmav1 in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 16, 2015, 10:28 PM
  3. Replies: 6
    Last Post: Jan 03, 2014, 5:48 AM
  4. [CLOSED] very strange null reference exception?
    By tobros in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 01, 2013, 2:04 AM
  5. Null Reference Exception in MVC
    By geraldf in forum 2.x Help
    Replies: 1
    Last Post: Sep 07, 2012, 6:11 PM

Posting Permissions