使用quartz.net如何更新执行的结果到界面上来。

jinfang134 2016-01-19 08:02:25
在winform中使用quartz框架,如何反馈执行的结果到界面上来?使执行的结果能够在界面上显示,是否执行成功等。。。
...全文
2027 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
anxingzhishang 2019-04-10
  • 打赏
  • 举报
回复
谢谢楼主分享,确实可用
VictorCheng6296 2017-03-02
  • 打赏
  • 举报
回复
终于搞定了 namespace Quartz { public delegate void Write(string msg); class ControlQueue { public bool update = false; public int job_times = 0; public Write myWrite; public void Display() { myWrite("job execute : "+ job_times.ToString() +" times\n"); } } } namespace Quartz { public class LoopControl { public bool loop; } class ControlJob : IJob { public void Execute(IJobExecutionContext context) { ControlQueue cq = (ControlQueue)context.JobDetail.JobDataMap.Get("ControlQueue"); LoopControl loop = null; // 任务循环变量 loop = (LoopControl)context.JobDetail.JobDataMap.Get("loopControlJob"); while (loop.loop) { if (cq.update) { cq.job_times++; Thread.Sleep(10); cq.update = false; } else Thread.Sleep(100); } } } } namespace Quartz { public partial class Form1 : Form { private ControlQueue cq; private IScheduler sched; private LoopControl loopControlJob; void DisplayJobtimes(string msg) { textBox1.BeginInvoke(new Action(() => { textBox1.AppendText(msg.ToString()); })); } public Form1() { InitializeComponent(); loopControlJob = new LoopControl(); loopControlJob.loop = true; cq = new ControlQueue(); cq.myWrite = DisplayJobtimes; ISchedulerFactory sf = new StdSchedulerFactory(); sched = sf.GetScheduler(); sched.Start(); IJobDetail job = JobBuilder.Create<ControlJob>().WithIdentity("ControlJob", "Test").StoreDurably().Build(); job.JobDataMap.Put("ControlQueue", cq); job.JobDataMap.Put("loopControlJob", loopControlJob); ITrigger trigger = TriggerBuilder.Create().WithIdentity("ControlTrigger", "Test").StartNow().Build(); sched.ScheduleJob(job, trigger); } private void button1_Click(object sender, EventArgs e) { timer1.Enabled = true; } private void timer1_Tick(object sender, EventArgs e) { cq.update = true; cq.Display(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { loopControlJob.loop = false; sched.Shutdown(); } private void button2_Click(object sender, EventArgs e) { timer1.Enabled = false; } } }
  • 打赏
  • 举报
回复
IScheduler scheduler;
scheduler.ListenerManager.AddJobListener
scheduler.ListenerManager.AddTriggerListener
scheduler.ListenerManager.AddSchedulerListener
  • 打赏
  • 举报
回复
有AddListerner啊
VictorCheng6296 2017-03-01
  • 打赏
  • 举报
回复
提示 错误 Delegate Write是 "类型", 但此处被当作 "变量" 使用!
VictorCheng6296 2017-03-01
  • 打赏
  • 举报
回复
@starfd @diaodiaop 有例程吗? 不会弄呀
VictorCheng6296 2017-02-28
  • 打赏
  • 举报
回复
引用 6 楼 diaodiaop 的回复:
[quote=引用 5 楼 czw6296 的回复:] 有例程吗? @diaodiaop

public delegate void Write(string msg);
然后在form1里定义如下

public static Write MyWrite;
        void Write(object msg)
        {
            richTextBox1.BeginInvoke(new Action(() =>
            {
                richTextBox1.Text += msg.ToString() + "\n";
            }));
        }
并且在窗体加载的时候 执行一下

MyWrite = Write;
这个时候 就算定义好了.. 然后 你在

public void Execute(Quartz.IJobExecutionContext context)
{
 Write("啊啊啊啊啊")
}
就行了[/quote] 提示 错误 Delegate Write是 "类型", 但此处被当作 "变量" 使用!
VictorCheng6296 2017-02-28
  • 打赏
  • 举报
回复
多谢了, 俺试一下哦
by_封爱 版主 2017-02-28
  • 打赏
  • 举报
回复
引用 5 楼 czw6296 的回复:
有例程吗? @diaodiaop

public delegate void Write(string msg);
然后在form1里定义如下

public static Write MyWrite;
        void Write(object msg)
        {
            richTextBox1.BeginInvoke(new Action(() =>
            {
                richTextBox1.Text += msg.ToString() + "\n";
            }));
        }
并且在窗体加载的时候 执行一下

MyWrite = Write;
这个时候 就算定义好了.. 然后 你在

public void Execute(Quartz.IJobExecutionContext context)
{
 Write("啊啊啊啊啊")
}
就行了
VictorCheng6296 2017-02-28
  • 打赏
  • 举报
回复
有例程吗? @diaodiaop
VictorCheng6296 2017-02-28
  • 打赏
  • 举报
回复
同问, 请高手回答一下哦
  • 打赏
  • 举报
回复
我也在处理这个问题。把委托事件卸载job的Execute,事件总是null报错。
瑞卡哥哥 2016-01-20
  • 打赏
  • 举报
回复
定义委托到job 中使用委托改变界面的值.
by_封爱 版主 2016-01-20
  • 打赏
  • 举报
回复
定义一个全局的委托..然后在job里就可以调用了.

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧