views:

167

answers:

0

Hi,

I have the following scenario with ASP.NET 2.0. I have declared an atlas:timer as follows in my .aspx page:

 <atlas:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="3000" 
                           Enabled="false"> </atlas:Timer>

I also have a button on a form which when clicked launches a new System.Threading.Thread and enables the timer like so:

protected void btn_Click(object sender, EventArgs e)
{
    Thread objThread = new Thread(new ThreadStart(MyRoutine));
    objThread.IsBackground = true;
    objThread.Start();
    Session["Thread"] = objThread;
    Timer1.Enabled = true;
}

protected void Timer1_Tick(object sender, EventArgs e)
{
    if (Session["var"] != null)
    {
        //Here I am doing an alert to indicate that I have entered the Tick event
        //Let's call this location in the code "TickLocation" for the argument...
        if ((int)Session["var"] != -1)
        {
             lbl.Text = "Progress: " + Convert.ToString(Session["var"]));
        }
        else
        {
            lbl.Text = "Done!";
            Timer1.Enabled = false;
        }
    }
}

I have reduced the thread routine "MyRoutine" to the following minimal code:

protected void MyRoutine()  
{  
    Session["var"] = 0;   

   /** The Timer1_Tick only fires once with the following (StreamWriter) line 
    of code, i.e. the alert in <b>"TickLocation"</b> is only shown once. I am 
    not receiving any exception as far as I can tell. If I comment out the 
    following line, the alerts are shown at intervals of 3000ms (the timer 
    interval), correctly  **/

    StreamWriter sw = File.AppendText(Server.MapPath("./uploads/MyFile.txt");  
}

This is on the live server. In my development environment, I have a much more complex "MyRoutine" and everything works fine, with the timer events firing properly (despite having the same Server.MapPath logical flow). So, I was thinking that maybe the live server does not like the Server.MapPath line? It's like it's locking further execution of the program.

Any help would be greatly appreciated.

Thanks!
Tim