possible timeout issues when using my ui

Posted on 2008-10-01
Last Modified: 2012-05-05

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.
Question by:scm0sml
  • 2
LVL 18

Expert Comment

Comment Utility

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.


Author Comment

Comment Utility
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?
LVL 18

Accepted Solution

carlnorrbom earned 500 total points
Comment Utility

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


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">

    <title>Background Worker Thread Test</title>



    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">


    <div style="border: Solid 1px Gray;padding: 5px 5px 5px 5px;margin-top: 50px;">

        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">


                <div id="processDiv" runat="server">




                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />



        <asp:Button ID="btnStartProcess" Text="Start Background Process" runat="server" />

        <asp:Timer ID="Timer1" runat="server" Interval="1000">







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")))))


            i += 1


        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)


            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


Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now