PDA

View Full Version : [CLOSED] Progressbar - NullReferenceException when trying to call anothers project function



jamesand
Sep 27, 2013, 12:53 PM
Hi, I'm trying to use ProgressBar control in my project, and everything goes ok when testing, but when I try to use it in a real scenario it crashes if I try to invoke a function in another projct of the same solution.

Here it is the code of the function "LongAction" modified:


Private Sub LongAction()

Dim interfazAbonos As New Negocio.InterfazAbonos()

For i = 0 To 10
Threading.Thread.Sleep(1000)
Session("LongActionProgress") = i + 1
Next

Session.Remove("LongActionProgress")

End Sub

Negocio is a project in the same solution. And it crashes at that line.

Any ideas?

Daniil
Sep 27, 2013, 5:33 PM
Hi @jamesand,

Please post the full Stack Trace of the Exception. Maybe, it can clarify something.

jamesand
Sep 30, 2013, 1:16 PM

Daniil
Sep 30, 2013, 3:14 PM
Do you call a WebService? You might need to enable Session.
http://stackoverflow.com/questions/7545711/asp-net-c-sharp-httpcontext-current-session-is-null-inside-webservice

jamesand
Sep 30, 2013, 4:32 PM

Baidaly
Sep 30, 2013, 8:39 PM
Hello!

Please, check the value of 'mensaje' variable. It shouldn't be null. If it doesn't then check that all other variables are not null.

jamesand
Sep 30, 2013, 9:05 PM
Hello!

Please, check the value of 'mensaje' variable. It shouldn't be null. If it doesn't then check that all other variables are not null.

Hi Baidaly, thanks for your reply. "mensaje" has value, and it crashes when calling "Notification.Show(config)". It's very weird. Only happening when calling a progressbar function.

Stack trace:

en Ext.Net.ScriptClass.AddScript(String script)
en Ext.Net.ScriptClass.Render()
en Ext.Net.Notification.Show()
en Ext.Net.Notification.Show(NotificationConfig config)

Baidaly
Sep 30, 2013, 10:31 PM
Couldn't reproduce your issue using the sample below. Can you check the width of your config. If you still have this issue provide a sample to reproduce:


<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET Examples</title>

<script runat="server">
public static string stub = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ...";

protected void Button1_Click(object sender, DirectEventArgs e)
{
NotificationConfig config = new NotificationConfig
{
Title = "Error",
Icon = Icon.Error,
AutoHide = false,
Html = stub,
Width = 1000
};
Notification.Show(config);
}
</script>
</head>
<body>
<ext:ResourceManager runat="server" ScriptMode="Debug" />

<ext:Button runat="server" ID="Button1" Text="Show button">
<DirectEvents>
<Click OnEvent="Button1_Click"></Click>
</DirectEvents>
</ext:Button>
</body>
</html>

jamesand
Oct 01, 2013, 8:01 AM
The thing is that Notification works as expected everywhere in my project except in the function called by LongAction, following this example:

http://examples2.ext.net/#/Miscellaneous/ProgressBar/Server_Side_Update/

Daniil
Oct 01, 2013, 8:25 AM
We would like to investigate it. If you cannot provide us with a simplified test case, then it might be an option to provide us with an entire test project. Please simplify it as well and share somewhere to download.

jamesand
Oct 01, 2013, 9:08 AM
We would like to investigate it. If you cannot provide us with a simplified test case, then it might be an option to provide us with an entire test project. Please simplify it as well and share somewhere to download.

You are right Daniil. Here you have:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test3.aspx.vb" Inherits="Test3" %>

<%@ Import Namespace="System.Threading" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
Protected Sub StartLongAction(sender As Object, e As DirectEventArgs)
Session("LongActionProgress") = 0
ThreadPool.QueueUserWorkItem(New Threading.WaitCallback(AddressOf LongAction))
ResourceManager1.AddScript("{0}.startTask('longactionprogress');", TaskManager1.ClientID)
End Sub

Private Sub LongAction(state As Object)
For i = 0 To 9
Thread.Sleep(1000)
Session("LongActionProgress") = i + 1
Next

Session.Remove("LongActionProgress")

Dim config As New NotificationConfig
config.Title = "Error"
config.Icon = Ext.Net.Icon.Error
config.AutoHide = False
config.Html = "Finished!"
config.Width = "1000"
Notification.Show(config)

End Sub

Protected Sub RefreshProgress(sender As Object, e As DirectEventArgs)
Dim progress As Object = Session("LongActionProgress")

If Not progress Is Nothing Then
Progress1.UpdateProgress((DirectCast(progress, Integer)) / 10.0F, String.Format("Step {0} of {1}...", progress.ToString(), 10))
Else
ResourceManager1.AddScript("{0}.stopTask('longactionprogress');", TaskManager1.ClientID)
Progress1.UpdateProgress(1, "All finished!")
End If
End Sub
</script>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<title>ProgressBar - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<h1>Progress Bar</h1>

<p>The example shows how to update the ProgressBar during long server-side actions.</p>

<ext:Button
ID="ShowProgress1"
runat="server"
Text="Start long action"
OnDirectClick="StartLongAction"
/>

<br />

<ext:ProgressBar ID="Progress1" runat="server" Width="300" />

<ext:TaskManager ID="TaskManager1" runat="server">
<Tasks>
<ext:Task
TaskID="longactionprogress"
Interval="1000"
AutoRun="false"
OnStart="
#{ShowProgress1}.setDisabled(true);"
OnStop="
#{ShowProgress1}.setDisabled(false);">
<DirectEvents>
<Update OnEvent="RefreshProgress" />
</DirectEvents>
</ext:Task>
</Tasks>
</ext:TaskManager>

</form>
</body>
</html>
</html>

Daniil
Oct 01, 2013, 3:37 PM
Well, the LongAction is executing in a separate thread. Client side, i.e. browser, doesn't get any response from that thread.

If it were possible, then, for example, this action could be done within the LoadAction method.

Progress1.UpdateProgress((DirectCast(progress, Integer)) / 10.0F, String.Format("Step {0} of {1}...", progress.ToString(), 10))

But no, it is done in another method, i.e. RefreshProgress, which has the connection with a browser.

jamesand
Oct 02, 2013, 10:55 AM
Ok, I will workaround.

Thank you all