?
Solved

possible timeout issues when using my ui

Posted on 2008-10-01
3
Medium Priority
?
235 Views
Last Modified: 2012-05-05
Hi,

We currently have a piece of sql that runs that can take a long time, over minutes wouldnt be unusual purely due to the amount of data that is being processed.

I have been asked to put a quick user interface together just so that marketing can kick this job off them selves.

So basically on a button click i will be calling a stored procedure that will run this sql.

What i am worried about is the amount og time it takes to run, will the code timeout etc?

what is the best way to handle this kind of thing? A thread or webservice or?.....

This is the first time I have had to do something that comes up against this issue so dont know what the 'norm' is for handling.

any advice would be appreacited on best practice or at how it would normally be handled.

I would need to some how let the user know that the job has finished via the ui.
0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 22612526
Hi,

First of all, will the UI be a winform or a webform? Secondly, regardless of question one, putting it on a separate worker thread will separate it from the UI.

/Carl.
0
 

Author Comment

by:scm0sml
ID: 22612540
It will be a webform.

Will the worker thread be able to report back to the ui to display some notification that it is completed?
0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 2000 total points
ID: 22613987
Hi,

Yes, please consider the attached code snippet for reference on how to set it up.

/Carl.
WorkerThreadPage.aspx:
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="WorkerThreadPage.aspx.vb" Inherits="WorkerThreadPage" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Background Worker Thread Test</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div style="border: Solid 1px Gray;padding: 5px 5px 5px 5px;margin-top: 50px;">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
            <ContentTemplate>
                <div id="processDiv" runat="server">
                </div>           
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>
        <asp:Button ID="btnStartProcess" Text="Start Background Process" runat="server" />
        <asp:Timer ID="Timer1" runat="server" Interval="1000">
        </asp:Timer>
    </div>
    </form>
</body>
</html>
 
WorkerThreadPage.aspx.vb:
 
Imports System.Threading
 
Partial Class WorkerThreadPage
    Inherits System.Web.UI.Page
 
    Private Event ThreadCompleted()
    Private Event ThreadProgress(ByVal threadProgress As Double)
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim wThread As Thread = New Thread(AddressOf DoBackgroundWork)
            wThread.IsBackground = True
            Session("WorkerThread") = wThread
            AddHandler ThreadCompleted, AddressOf WorkerThreadCompleted
            AddHandler ThreadProgress, AddressOf WorkerThreadProgress
            Timer1.Enabled = False
            Session("IsComplete") = False
            Session("MaxRunningTime") = 100
            Session("ThreadProgress") = 0
        End If
        If Page.IsPostBack Then
            If (CType(Session("WorkerThread"), Thread).IsAlive = True) And (CType(Session("IsCompleted"), Boolean) = True) Then
                CType(Session("WorkerThread"), Thread).Abort()
            End If
        End If
    End Sub
 
    Protected Sub btnStartProcess_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStartProcess.Click
        CType(Session("WorkerThread"), Thread).Start()
        processDiv.InnerText = "Processing Background Worker Thread, Status: 0%"
        Timer1.Enabled = True
    End Sub
 
    Private Sub DoBackgroundWork()
        Dim i As Integer = 0
        Do While i < CInt(Session("MaxRunningTime")) + 1
            If (i = CInt(Session("MaxRunningTime"))) Then
                RaiseEvent ThreadCompleted()
            End If
            RaiseEvent ThreadProgress(CDbl(100 * (i / CInt(Session("MaxRunningTime")))))
            Thread.Sleep(1000)
            i += 1
        Loop
        i = 0
    End Sub
 
    Private Sub WorkerThreadCompleted()
        Session("IsCompleted") = True
    End Sub
 
    Private Sub WorkerThreadProgress(ByVal threadProgress As Double)
        If threadProgress.ToString.Length > 5 Then
            Session("ThreadProgress") = threadProgress.ToString.Substring(0, 5)
        Else
            Session("ThreadProgress") = threadProgress.ToString
        End If
    End Sub
 
    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        processDiv.InnerText = "Processing Background Worker Thread, Status:" & Session("ThreadProgress").ToString & "%"
        If Session("IsCompleted") Then
            processDiv.InnerText = "Processing Background Worker Thread, Status: Finished!"
            Timer1.Enabled = False
        End If
    End Sub
 
End Class

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question