是否需要在global里,做一个timer啊。
这是生成静态的方法
public void Dohtml(string Ourl, string Path)
我在global调用:
BLL.BLL hh = new BLL.BLL();
hh.Dohtml("http://localhost/default.aspx", System.Web.HttpContext.Current.Server.MapPath("./"));但是不成功。在百度,google里搜索了无数次,仍为找到答案。请高手赐教。
-------------------------------------------------------------我global里的代码是这样的:
protected void Application_Start(object sender, EventArgs e)
{ // 在应用程序启动时运行的代码
System.Timers.Timer myTimer = new System.Timers.Timer(1000 * 1 * 1);
myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);//时间到了执行
myTimer.Interval = 1000 * 1 * 1;
myTimer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件
myTimer.AutoReset = true;
// t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
}
private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
try
{
BLL.BLL hh = new BLL.BLL();
hh.Dohtml("http://localhost/hengshuirc/default.aspx", System.Web.HttpContext.Current.Server.MapPath("./"));
}
catch { }
}
这是生成静态的方法
public void Dohtml(string Ourl, string Path)
我在global调用:
BLL.BLL hh = new BLL.BLL();
hh.Dohtml("http://localhost/default.aspx", System.Web.HttpContext.Current.Server.MapPath("./"));但是不成功。在百度,google里搜索了无数次,仍为找到答案。请高手赐教。
-------------------------------------------------------------我global里的代码是这样的:
protected void Application_Start(object sender, EventArgs e)
{ // 在应用程序启动时运行的代码
System.Timers.Timer myTimer = new System.Timers.Timer(1000 * 1 * 1);
myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);//时间到了执行
myTimer.Interval = 1000 * 1 * 1;
myTimer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件
myTimer.AutoReset = true;
// t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
}
private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
try
{
BLL.BLL hh = new BLL.BLL();
hh.Dohtml("http://localhost/hengshuirc/default.aspx", System.Web.HttpContext.Current.Server.MapPath("./"));
}
catch { }
}
解决方案 »
- 用c#封装access的连接为com组件供c++调用,但是c#中的dataset等关键字,在c++认为是IUnknownPtr
- c#怎么建立一个txt输出文件,并将数组结果写入呢?
- 我又来问一个刁的问题!如果将html网页上显示插入状态的光标,并且回车可以将文本换行,谢谢。
- C#中,win,访问Access数据库,运行报错的问题
- 关于HttpRequest向表单发送数据报的问题(Post方式)
- 从数据集更新oracle数据库出错,求救。
- Socket.select() 的问题
- 求救***鼠标锁定问题***求救***顶者有分***
- C#写的小程序中怎么与.net框架一起打包成安装程序???急急!!!!!!
- 我发现:CSDN.NET好象非常的乱,谈的东西大都没多大用处
- C#可以支持GPS地图吗?
- Directory.GetFiles选文件时“排除”文件的问题???
楼主应该知道在托管环境下如果你的前台线程执行完后,那么依赖前台线程的后台线程也会自动被abort掉,除非你在主线程中阻塞一下,等待后台线程的完成。
最好把上下文获取本地路径放到主线程中,然后作为参数传到从线程中,以下是简单的调用,这里如果参数太多或是复杂参数,你可以构造一个线程辅助类,将所有的参数放到辅助对象中,作为state的参数
protected void Application_Start(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
string mappath = context.Server.MapPath("static");
Timer time = new Timer(new TimerCallback(CreateToStaticHtml), mappath, 1000, 5000);
}
private void CreateToStaticHtml(object state)
{
FileStream fs = new FileStream(string.Format("{0}/{1}.html",state.ToString(), DateTime.Now.ToString().Replace("-","").Replace(":","").Replace(" ","")),FileMode.OpenOrCreate, FileAccess.Write,FileShare.Read);
StreamWriter sw = new StreamWriter(fs);
sw.Write("dfghjkl;dfghjkl");
sw.Close();
}