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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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.Start();
    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.

    Thanks,
  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"

    index.aspx
    <%@ Page Language="C#" %>
    
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            new WebApplication4.ViewModels.TestWindow().Render(true);
        }
    
    </script>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    </body>
    </html>
    TestWindow.cs
    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/";
    
                Items.Add(valBtn);
            }
    
        }
    }
    ExtNetController
    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.Start();
                t.ContinueWith(task => Result(task.Result));
    
                return this.Direct();
            }
    
            private string Validation()
            {
                Thread.Sleep(5000);
    
                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