Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于调度使用.stop()后再次执行.start()的问题 #11

Open
sensentw opened this issue Apr 27, 2023 · 1 comment
Open

关于调度使用.stop()后再次执行.start()的问题 #11

sensentw opened this issue Apr 27, 2023 · 1 comment

Comments

@sensentw
Copy link

public XiaoFeng.Threading.Job emailserver =new XiaoFeng.Threading.Job();

private void emailstart()
{

        emailserver.Async = true;
        emailserver.Name = "邮件服务";
        emailserver.TimerType = XiaoFeng.Threading.TimerType.Interval;
        emailserver.Period = 5000;
        emailserver.StartTime = DateTime.Now;
        emailserver.SuccessCallBack = job =>
        {
            /*到时间执行任务*/

            MailReceive();


        };
        emailserver.Start();
       

    }

private void button1_Click(object sender, EventArgs e)
{

        //timer1.Enabled = Enabled;
        if (emailserver.Status == XiaoFeng.Threading.JobStatus.NotQueued||emailzt==false)
        {
          
             emailserver.Start();//第二步,执行这里的时候就无法再次运行了
            //emailstart() ;使用此方法同样无法在启动了
        }
        else
        {
            emailserver.Stop();//第一步,这里执行会正常停止
           
        }

      }
@zhuovi
Copy link
Owner

zhuovi commented Apr 27, 2023

作业调度代码如下,实现在启用,停止,再启用

var MyJob = new Job
{
    Name ="我的作业",
    Period=2000, TimerType= TimerType.Interval,
    SuccessCallBack = j =>
    {
        Console.WriteLine($"执行了作业{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff")}");
    },
    StopCallBack = j =>
    {
        Console.WriteLine($"停止了作业{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff")}");
    }
};

Task.Run(() =>
{
    var i = 0;
    while (true)
    {
        if (i % 2 == 0)
            MyJob.Start();
        else
            MyJob.Stop();


        Task.Delay(10000).Wait();
        i++;
    }
});

Console.ReadLine();

下图为当前代码运行日志

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants