Edited by SomeNewKid. Please post code between <code> and </code> tags.
Hallo, I have 2 IIS Server. On both i have a asp.net script. The first script on the first server connects to the second script on the second server ba an HttpWebRequest-objects. The second asp.net-script sends the xml-answer by Response.Write(). My problem
is now that i have to get a thread doing more work after the second script has ended. So before the end of the second script i instanciate a new Thread by a own c#-class.
ResponseRequester responseRequester = new ResponseRequester();
responseRequester.setAbsolutePath(Server.MapPath("."));
responseRequester.setURL(url);
responseRequester.confirm();
The class starts the Thread:
using System;
using System.Collections;
using System.Threading;
using System.Xml;
namespace tinasimulator
{
///
/// Summary description for ResponseRequester.
///
public class ResponseRequester
{
///
/// The url to send the request to.
///
private string url = "";
private Thread confirmer = null;
private string absolutePath = "";
public ResponseRequester()
{
}
public void setAbsolutePath(string absolutePath)
{
this.absolutePath = absolutePath;
}
///
///Sets the url to connect to.
///
public void setURL(String url)
{
this.url = url;
}
///
///start the thread to connect to the tinasimulator.
///
public void confirm()
{
try
{
this.confirmer = new Thread(new ThreadStart(this.send));
this.confirmer.Name = "confirmer";
this.confirmer.Priority = ThreadPriority.Highest;
this.confirmer.Start();
Logger.log("Thread started");
}
catch(Exception e)
{
Logger.log(e.ToString());
}
}
public void send()
{
Thread.sleep(5000);
//read the server data from a file
ConfigLoader configLoader = new ConfigLoader();
Hashtable config = configLoader.loadConfig //send the request
ServerConnector serverConnector = new ServerConnector();
string requestEndXML =
"......";
XmlDocument requestEndXMLDocument = new requestEndXMLDocument.LoadXml(requestEndXML);
serverConnector.sendRequest(requestEndXMLDocument, url, (String) config["user"], (String) config["password"]);
}
}
}
The class Server connector connects to another server. I can't do it in another
way - sorry. So my problem is that after the page is left the thread crashes. VS.NET2003 says: "An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object reference not set to an instance of an
object." So what i am doing wrong to get the thread be alive after the page is over? Thanks for any help.
A6Sr
Member
5 Points
1 Post
Threads on leaving the asp.net page
Aug 24, 2004 02:43 PM|LINK
Hallo, I have 2 IIS Server. On both i have a asp.net script. The first script on the first server connects to the second script on the second server ba an HttpWebRequest-objects. The second asp.net-script sends the xml-answer by Response.Write(). My problem is now that i have to get a thread doing more work after the second script has ended. So before the end of the second script i instanciate a new Thread by a own c#-class.
ResponseRequester responseRequester = new ResponseRequester(); responseRequester.setAbsolutePath(Server.MapPath(".")); responseRequester.setURL(url); responseRequester.confirm();The class starts the Thread:using System; using System.Collections; using System.Threading; using System.Xml; namespace tinasimulator { ///
/// Summary description for ResponseRequester.
///
public class ResponseRequester
{
///
/// The url to send the request to.
///
private string url = "";
private Thread confirmer = null;
private string absolutePath = "";
public ResponseRequester()
{
}
public void setAbsolutePath(string absolutePath)
{
this.absolutePath = absolutePath;
}
///
///Sets the url to connect to.
///
public void setURL(String url)
{
this.url = url;
}
///
///start the thread to connect to the tinasimulator.
///
public void confirm()
{
try
{
this.confirmer = new Thread(new ThreadStart(this.send));
this.confirmer.Name = "confirmer";
this.confirmer.Priority = ThreadPriority.Highest;
this.confirmer.Start();
Logger.log("Thread started");
}
catch(Exception e)
{
Logger.log(e.ToString());
}
}
public void send()
{
Thread.sleep(5000);
//read the server data from a file
ConfigLoader configLoader = new ConfigLoader();
Hashtable config = configLoader.loadConfig //send the request
ServerConnector serverConnector = new ServerConnector();
string requestEndXML =
"......";
XmlDocument requestEndXMLDocument = new requestEndXMLDocument.LoadXml(requestEndXML);
serverConnector.sendRequest(requestEndXMLDocument, url, (String) config["user"], (String) config["password"]);
}
}
}The class Server connector connects to another server. I can't do it in another way - sorry. So my problem is that after the page is left the thread crashes. VS.NET2003 says: "An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object reference not set to an instance of an object." So what i am doing wrong to get the thread be alive after the page is over? Thanks for any help.