111,130
社区成员
发帖
与我相关
我的任务
分享
<Webs>
<Web>
<WebName>找供应</WebName>
<WebUrl>http://www.myweb.com/</WebUrl>
<WebTime>30</WebTime>
</Web>
<Web>
<WebName>找求购</WebName>
<WebUrl>http://www.myweb3.com/</WebUrl>
<WebTime>10</WebTime>
</Web>
<Web>
<WebName>找公司</WebName>
<WebUrl>http://www.myweb3.com/</WebUrl>
<WebTime>10</WebTime>
</Web>
</Webs>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Xml;
using System.Threading;
using System.Web;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Data.SqlClient;
namespace WServiceMk_html
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
System.Threading.Thread.Sleep(10000);
string filepath = System.Windows.Forms.Application.StartupPath + "\\XmlData.xml";
DataSet ds = new DataSet();
ds.ReadXml(filepath);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
//arylst.Clear();
System.Threading.Timer tm;
int WebTime = Convert.ToInt32(ds.Tables[0].Rows[i]["WebTime"].ToString());
ArrayList arylst = new ArrayList();
arylst.Add(ds.Tables[0].Rows[i]["WebName"].ToString());
arylst.Add(ds.Tables[0].Rows[i]["WebUrl"].ToString());
tm = new System.Threading.Timer(new TimerCallback(TimerTest), arylst, 0, WebTime * 6);
//System.Configuration.ConfigurationSettings.AppSettings
}
}
protected override void OnStart(string[] args)
{
}
private void TimerTest(object obj)
{
ArrayList list = (ArrayList)obj;
SqlConnection con = new SqlConnection("server=.;uid =sa;pwd=111111;database=dataTest");
con.Open();
string sql;
sql = "insert into TestTimer values('" + list[0].ToString() + "','" + list[1].ToString() + "')";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
}
protected override void OnStop()
{
}
}
}
System.Threading.Timer tr;
tr = new System.Threading.Timer(new TimerCallback(GetData), null, 1000, 600000);
private void GetData(object o)
{
//处理数据
}