我在委托的函数中调用 System.Web.HttpContext.Current.Server 就会报错.而且是Web异常.问题就在于没有找到Server 对象,请知道的朋友告诉我下
private System.Threading.Timer UpdateTimer = null;
public void Start()
{
if (UpdateTimer == null)
{
UpdateTimer = new System.Threading.Timer(new TimerCallback(UpdateTimerCallback), null, Interval, Interval);
}
}
private void UpdateTimerCallback(object sender)
{
if (Interlocked.Exchange(ref _IsRunning, 1) == 0)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(System.Web.HttpContext.Current.Server.MapPath("emailInfo.xml"));
try
{
string sql = "select * from EmailSendNote where emailType=1 ";
DataSet ds = sh.ExecuteDataSet(sql);
if (ds.Tables[0].Rows.Count<1)
private System.Threading.Timer UpdateTimer = null;
public void Start()
{
if (UpdateTimer == null)
{
UpdateTimer = new System.Threading.Timer(new TimerCallback(UpdateTimerCallback), null, Interval, Interval);
}
}
private void UpdateTimerCallback(object sender)
{
if (Interlocked.Exchange(ref _IsRunning, 1) == 0)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(System.Web.HttpContext.Current.Server.MapPath("emailInfo.xml"));
try
{
string sql = "select * from EmailSendNote where emailType=1 ";
DataSet ds = sh.ExecuteDataSet(sql);
if (ds.Tables[0].Rows.Count<1)
解决方案 »
- HTML页面falsh显示大小的问题
- webconfig 连接字符串问题
- web.config中连接字符串的问题
- Response.Redirect的问题
- asp.net 如何获得datagrid页脚值的方法
- 求页面加载的处理代码(ASP.NET C#)
- enterprise Library 2.0没有SQLHelper或ADOHelper了?
- asp.net如何提取服务器端时间,不停的显示在浏览器上?
- 我在webmatrixhosting.net上申请的免费.net空间,申请的时候不是codebehind,现在想用codebehind,请问如何解决?
- js对word的操作 (求解 ...急....)
- Coolite里的GridPanel手动动态的添加列的问题?
- 急急急急!!连发两贴问题还未解决,再发一新帖,向各位求解:asp.net开发wap网站,selectionlist1_selectIndexChange响应事件
if (System.Web.HttpContext.Current == null || System.Web.HttpContext.Current.Server == null)
{
return;
}
作判断,结果执行了return
为当前 HTTP 请求获取或设置 HttpContext 对象。 你这里没有请求,不能使用 HttpContext 对象
那就加一个属性,将当前的Application或者System.Web.HttpContext.Current传递进去
private System.Threading.Timer UpdateTimer = null;
private int _IsRunning;
SqlHelper sh = new SqlHelper();
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
UpdateTimer = new System.Threading.Timer(new System.Threading.TimerCallback(UpdateTimerCallback), null, 1000, 1000);
}
private void UpdateTimerCallback(object sender)
{
if (System.Threading.Interlocked.Exchange(ref _IsRunning, 1) == 0)
{
System.Web.HttpContext.Current.Application["sentType"] = "aaa";
try
{
string sql = "select * from EmailSendNote where emailType=1 ";
System.Data.DataSet ds = sh.ExecuteDataSet(sql);
if (ds.Tables[0].Rows.Count < 1)
{