473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Unable to start thread from ASP.net app with windows server 2003

I have an asp.net application that needs to spawn a new thread but
return the response back to the user before the thread finishes. My
application works fine on my machine (XP pro) and on a win 2000 server,
but I can't get a thread to start on a new win 2003 server. I've
posted some sample code below. I've made sure that the user this runs
under has permission to write the test file to the c: drive. This code
works on all the servers if I don't start a new thread but call the
WriteFile method directly.

I'm sure I've missed a security setting somewhere, I know 2003 is
supposed to be tied down a little tighter than it's predecessors.
Any help would be appreciated. Thanks in advance!

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.IO;

namespace TestApp
{
/// <summary>
/// Summary description for Test.
/// </summary>
public class Test : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("beginning thread<br>");
ThreadStart ts = new ThreadStart(WriteFile);
Thread t = new Thread(ts);
t.Start();
Response.Write("began thread<br>");
}

private void WriteFile()
{
StreamWriter sw = File.CreateText("c:\\test.txt");
sw.WriteLine("test - "+ DateTime.Now.ToLongTimeString());
sw.Close();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}

Nov 19 '05 #1
5 1241
Just wanted to add - I don't get any errors, the application appears to
run normally, but it won't write that file, so I assume the thread is
never really created or it silently fails somehow.

Nov 19 '05 #2
<to**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have an asp.net application that needs to spawn a new thread but
return the response back to the user before the thread finishes. My
application works fine on my machine (XP pro) and on a win 2000 server,
but I can't get a thread to start on a new win 2003 server. I've
posted some sample code below. I've made sure that the user this runs
under has permission to write the test file to the c: drive. This code
works on all the servers if I don't start a new thread but call the
WriteFile method directly.


Are you aware that WriteFile may well be executing after the request is
complete? At that time, the Page, Request, etc. are all garbage. This could
have something to do with your problem.

However, the next step would be for you to put a try-catch block around the
code in WriteFile and find out what if any exception is being thrown. Same
with Page_Load.

John Saunders
Nov 19 '05 #3
Will it be garbage as there is a root to the WriteFile method that would
keep the page around longer than necessary?

bill

"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
<to**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have an asp.net application that needs to spawn a new thread but
return the response back to the user before the thread finishes. My
application works fine on my machine (XP pro) and on a win 2000 server,
but I can't get a thread to start on a new win 2003 server. I've
posted some sample code below. I've made sure that the user this runs
under has permission to write the test file to the c: drive. This code
works on all the servers if I don't start a new thread but call the
WriteFile method directly.
Are you aware that WriteFile may well be executing after the request is
complete? At that time, the Page, Request, etc. are all garbage. This

could have something to do with your problem.

However, the next step would be for you to put a try-catch block around the code in WriteFile and find out what if any exception is being thrown. Same
with Page_Load.

John Saunders

Nov 19 '05 #4
"William F. Robertson, Jr." <th****@nameht.org> wrote in message
news:OQ**************@TK2MSFTNGP11.phx.gbl...
Will it be garbage as there is a root to the WriteFile method that would
keep the page around longer than necessary?
It can be whatever ASP.NET wants it to be. The point is, ASP.NET has no
support for accessing these resources after the request has completed. It
would be irresponsible to depend on whether the data happen not to be trash
in this particular release of ASP.NET.

The general solution is, "don't do that". Understand that such data may not
be accessed from a separate thread, and make sure the thread doesn't access
it.

John Saunders

"John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
<to**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
>I have an asp.net application that needs to spawn a new thread but
> return the response back to the user before the thread finishes. My
> application works fine on my machine (XP pro) and on a win 2000 server,
> but I can't get a thread to start on a new win 2003 server. I've
> posted some sample code below. I've made sure that the user this runs
> under has permission to write the test file to the c: drive. This code
> works on all the servers if I don't start a new thread but call the
> WriteFile method directly.


Are you aware that WriteFile may well be executing after the request is
complete? At that time, the Page, Request, etc. are all garbage. This

could
have something to do with your problem.

However, the next step would be for you to put a try-catch block around

the
code in WriteFile and find out what if any exception is being thrown.
Same
with Page_Load.

John Saunders


Nov 19 '05 #5
Ok, I fixed it and I'm not sure why. My issue was not in creating the
thread, but a file access permission problem. I did the try catch
block in WriteFile as John suggested and wrote the error out to a
variable which I could output to the page after doing a Join() to get
the thread back to the host. The strange thing is if I write to the
file without doing it in a separate thread it works fine, but I get an
access problem when I do it in a new thread. I changed the file to be
in one folder off the c drive, like this: c:\testfolder\test.txt and
that works fine.
So I still don't understand it completely, but this change fixed it.
Maybe server 2003 treats the root drive with different security
parameters than a folder, and it differs from xp and 2000 in this way.
Or, it treats spawned threads with different security privileges
somehow. Or, as John and William suggest, when the main request ends
and the thread is still going it loses access to the resources it used
originally which may have provided it access. That makes sense to me
but doesn't explain why it works with my fix. Oh well, I don't need to
write my log directly to the c drive anyway.
Thanks guys!

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tom wilson | last post by:
I've been through everything with this error and cannot get the debugger to work remotely. The only thing I can trace it down to is that RPC is not communicating between servers. So after many,...
3
by: David N | last post by:
I got a solution that contains about 30 projects, three of which cannot be open. When I open the project, I always receive the error message "Unable to get the project file from the Web Server" ...
1
by: Reza Sadeghi | last post by:
Hi I am getting this error when I tried to browse any asp.net in visual studio.net. I can build the project but when I try to run and debug the project I get error message that "Unable to start...
2
by: TM | last post by:
When I run an ASP.Net application I am getting the following error: "Error while trying to run project: Unable to start debugging on the web server. The project is not configured to be debugged."...
16
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the...
1
by: Báltico | last post by:
After installing Windows 2003 Server SP1 I was unable to start any asp.net project either in Debug or Release mode. Every time I got the Unable to start debugging on the web server ... You do not...
22
by: EP | last post by:
When running my asp.net hosting service (asp.net without IIS), on server 2003 with IIS not installed, I get the following when trying to process a request. "System.DllNotFoundException: Unable to...
7
by: Jed | last post by:
I am trying to open web project in VS 2003 using the File Share method. VS is running on XP Pro (Host) and I am accessing the root web of an XP Pro install on Virtual PC (Server) running on the...
4
by: richie | last post by:
Hi Everyone I have a problem with windows service I wrote which spawns a win32 program. the code in question looks like this: myProcess = new Process(); myProcess.StartInfo.FileName =...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.