美文网首页
asp.net控制网站定时更新数据的C#类的代码

asp.net控制网站定时更新数据的C#类的代码

作者: giveyoume | 来源:发表于2018-12-14 14:37 被阅读0次

    如下代码内容是关于asp.net控制网站定时更新数据的C#类的代码。

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Web;

    using System.Threading;

    namespace OKGO.Web

    {

        public class TestTimer

        {

             static int n = 0;

             public static Timer GlobalTimer = new Timer(new TimerCallback(GlobalTimer_ToDo), null, Timeout.Infinite, Timeout.Infinite);

             GlobalTimer.Interval = 10;

                     GlobalTimer.Enabled = true;

             static void GlobalTimer_ToDo(object obj)

             {

                 n = n + 1;

                if (n == 2)

                 {

                     System.Data.SqlClient.SqlDataReader dataReader = null;

                     try

                     {

                          System.IO.StreamReader sr = null;

                         string str=string.Empty;

                         dataReader = OKGO.DataAccess.SQLServer.ChannelProvider.Provider.GetAllRoleName();

                                 while (dataReader.Read() && dataReader.HasRows)

                                 {

                try

                {

                    System.Net.WebResponse myTemp = temp.GetResponse();

                    sr = new System.IO.StreamReader(myTemp.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"));

                    str = sr.ReadToEnd();

                    System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();

                    xmldoc.LoadXml(str);

                    System.Xml.XmlNode nodes = xmldoc.SelectSingleNode("Result");

                    if (Rolename == "")

                        continue;

                    OKGO.DataAccess.SQLServer.ChannelProvider.Provider.GetUpdateRoleName(int.Parse(dataReader["UserName"].ToString()), Rolename, RolenameTime);

                                         sr.Close();

                                         sr.Dispose();

                                         sr.Close();

                                     }

                                     catch (Exception ex)

                                     {

                                         throw ex;

                                     } 

                                 }

                     }

                     catch (Exception exc)

                     {

                         if (dataReader != null)

                         {

                             dataReader.Close();

                             dataReader.Dispose();

                         }

                         throw exc;

                     }

                     finally

                     {

                         if (dataReader != null)

                         {

                             dataReader.Close();

                             dataReader.Dispose();

                         }

                         n = 0;

                     }

                 }

             }

             public static void Start(long a, long b)

             {

                 GlobalTimer.Change(a, b);

             }

             public static void Stop()

            {

                 GlobalTimer.Change(Timeout.Infinite, Timeout.Infinite);

            }

        }

    }

    相关文章

      网友评论

          本文标题:asp.net控制网站定时更新数据的C#类的代码

          本文链接:https://www.haomeiwen.com/subject/rdlghqtx.html