定时任务

  1. 使用FluentSchduler库
  2. 继承Register类
  3. 在构造函数里使用Schedule(需要执行的任务函数).ToRunEvery()来指定运行时间
  4. 使用JobManager(new MyRegistery())来启动任务
namespace test
{
    public class HelloWorldTask: Registry
    {
        public HelloWorldTask()
        {
            //每秒钟执行一次PrintHelloWorld函数
            Schedule(PrintHelloWorld).ToRunEvery(1).Seconds();
        }
        private void PrintHelloWorld()
        {
            Console.WriteLine("Hello World!");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            JobManager.Initialize(new HelloWorldTask());
        }
    }
}

自动属性

//传统方法
private string _name;
public string Name
{
    get { return _name; }
    set { _name = value; }
}

//自动属性
public string Name { get; set; }

Yield

public static IEnumerable<int> Start()
{
    var random = new Random();
    int i = 0;
    while (true)
    {
        if (i > 100)
        {
            yield break;
        }
        yield return i;
        i++;
        Thread.Sleep(random.Next(5)*1000);
    }
}

基本类型转换

int a = 2;
a.ToString();

string a = "2";
int.Parse(a);

results matching ""

    No results matching ""