123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WCS.Workflow;
- namespace WCS.WFormServices
- {
- public partial class FromServices : Form
- {
- private delegate void UIRefresh(string message);//代理
- private event UIRefresh fc;//界面更新事件
- public FromServices()
- {
- InitializeComponent();
- this.fc += new UIRefresh(ThreadFunction);
- }
- private void ThreadFunction(string message)
- {
- this.lblMessage.Text = message;
- }
- private void btnStart_Click(object sender, EventArgs e)
- {
- Thread thread = new Thread(StartService);
- thread.Start();
- }
- private void StartService()
- {
- this.btnStart.Invoke(new MethodInvoker(delegate
- {
- this.btnStart.Enabled = false;
- this.btnClose.Enabled = false;
- }));
- try
- {
- this.Invoke(fc, new object[] { "WCS服务正在启动..." });//通过代理调用刷新方法
- InitWorkflow.InitData();
- QuartzStartup.Start().Wait();
- this.Invoke(fc, new object[] { "WCS服务正常启动,正在执行定时任务..." });//通过代理调用刷新方法
- }
- catch (Exception ex)
- {
- this.Invoke(fc, new object[] { ex.Message });//通过代理调用刷新方法
- this.btnStart.Enabled = true;
- }
- this.btnStart.Invoke(new MethodInvoker(delegate
- {
- this.btnClose.Enabled = true;
- }));
- }
- private void btnClose_Click(object sender, EventArgs e)
- {
- Thread thread = new Thread(StopService);
- thread.Start();
- }
- private void StopService()
- {
- this.btnStart.Invoke(new MethodInvoker(delegate
- {
- this.btnClose.Enabled = false;
- this.btnStart.Enabled = false;
- }));
- try
- {
- this.Invoke(fc, new object[] { "服务正在停止..." });//通过代理调用刷新方法
- QuartzStartup.Stop();
- this.Invoke(fc, new object[] { "服务已经停止。" });
- }
- catch (Exception ex)
- {
- this.Invoke(fc, new object[] { ex.Message });
- this.btnClose.Enabled = true;
- }
- this.btnStart.Invoke(new MethodInvoker(delegate
- {
- this.btnStart.Enabled = true;
- }));
- }
- private void FromServices_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- QuartzStartup.Stop();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
|