using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
namespace WorkFlow
{
public partial class Server : Form
{
private delegate void FlushClient();//代理
private delegate void ReadTime(); //设置时间代理
Thread thread = null;
Thread threadTime = null; //计时器
int counter = 0;
private static readonly string startTime = DateTime.Now.ToString();
public Server()
{
InitializeComponent();
}
/// <summary>
/// 加载load事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Server_Load(object sender, EventArgs e)
{
DoWorkList();
this.txtSetTime.Text = Convert.ToString(getTimeValue());
DoWorkTime();
}
#region 加载运行日志列表
/// <summary>
/// 线程工作
/// </summary>
public void DoWorkList()
{
thread = new Thread(CrossThreadFlush);
thread.IsBackground = true;
thread.Start();
}
private void CrossThreadFlush()
{
while (true)
{ //将sleep和无限循环放在等待异步的外面
Thread.Sleep(getTimeValue());
ThreadFuntion();
}
}
/// <summary>
/// 获取数据
/// </summary>
/// <returns></returns>
public void ThreadFuntion()
{
if (this.dtReadList.InvokeRequired)//等待异步
{
FlushClient fc = new FlushClient(ThreadFuntion);
this.Invoke(fc); //通过代理调用刷新方法
}
else
{
counter += 1;
WorkFlow workflow = new WorkFlow();
Hashtable ht = new Hashtable();
// ht.Add("ID","");
// workflow.SaveWorkFlow(ht);
int index = this.dtReadList.Rows.Add();
this.dtReadList.Rows[index].Cells[0].Value = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm:ss");
this.dtReadList.Rows[index].Cells[1].Value = counter; //workflow.GetAllOrderData().Tables[0].Rows.Count ;
}
}
#endregion
#region 查看程序已运行时间
/// <summary>
/// 加载
/// </summary>
public void DoWorkTime()
{
this.lblTime.Text = DateTime.Now.ToString("yyyy年mm月dd日 HH:mm:ss");
threadTime = new Thread(timeThread);//开启时间线程
threadTime.IsBackground = true;
threadTime.Start();
}
/// <summary>
/// 时间线程
/// </summary>
private void timeThread()
{
while (true)
{ //将sleep和无限循环放在等待异步的外面
Thread.Sleep(1000);
TimeThreadFuntion();
}
}
/// <summary>
/// 时间计算方式
/// </summary>
public void TimeThreadFuntion()
{
if (this.dtReadList.InvokeRequired)//等待异步
{
FlushClient fc = new FlushClient(TimeThreadFuntion);
this.Invoke(fc); //通过代理调用刷新方法
}
else
{
DateTime beginTime1 = DateTime.Parse(startTime);
DateTime endTime1 = DateTime.Parse(DateTime.Now.ToString());
TimeSpan midTime = endTime1 - beginTime1;
this.txtGetTime.Text = midTime.ToString();
}
}
#endregion
#region 设置每次执行的时间
/// <summary>
/// 设置时间
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSetTime_Click(object sender, EventArgs e)
{
Thread.Sleep(3000);
XmlDocument xmlDoc = new XmlDocument(); //声明xml
xmlDoc.Load("SetTimeXMLFile.xml");
//获取bookshop节点的所有子节点
XmlNodeList nodeList = xmlDoc.SelectSingleNode("setTime").ChildNodes;
//遍历所有子节点
foreach (XmlNode xn in nodeList)
{
XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型
XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach (XmlNode xn1 in nls)//遍历
{
XmlElement xe2 = (XmlElement)xn1; //转换类型
if (xe2.Name == "value")//如果找到
{
xe2.InnerText = this.txtSetTime.Text;//则修改
break;
}
}
}
xmlDoc.Save("SetTimeXMLFile.xml"); //保存其更改
MessageBox.Show("设置成功");
Thread.Sleep(1000);
}
/// <summary>
/// 获取时间
/// </summary>
/// <returns></returns>
public static int getTimeValue()
{
int time = 50000;
XmlDocument xmlDoc = new XmlDocument(); //声明xml
xmlDoc.Load("SetTimeXMLFile.xml");
//获取bookshop节点的所有子节点
XmlNodeList nodeList = xmlDoc.SelectSingleNode("setTime").ChildNodes;
//遍历所有子节点
foreach (XmlNode xn in nodeList)
{
XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型
XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点
foreach (XmlNode xn1 in nls)//遍历
{
XmlElement xe2 = (XmlElement)xn1; //转换类型
if (xe2.Name == "value")//如果找到
{
time = Convert.ToInt32(xe2.InnerText);
break;
}
}
}
return time;
}
#endregion
}
}
- 一个简单的webservice的demo(下)winform异步调用webservice
绕了一大圈,又开始接触winform的项目来了,虽然很小吧.写一个winform的异步调用webservice的demo,还是简单的. 一个简单的Webservice的demo,简单模拟服务 一个简单 ...
- Winform 异步调用
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 用Html5/CSS3做Winform,一步一步教你搭建CefSharp开发环境(附JavaScript异步调用C#例子,及全部源代码)上
本文为鸡毛巾原创,原文地址:http://www.cnblogs.com/jimaojin/p/7077131.html,转载请注明 CefSharp说白了就是Chromium浏览器的嵌入式核心,我们 ...
- WinForm查询大数据界面假死,使用异步调用解决
用DataGridView无分页绑定一个几千条数据的查询,查询的时候界面直接卡死十几秒,用户体验非常不好,因此用异步操作解决界面卡死的问题原本场景:点击[查询]后,界面直接卡死优化场景:点击[查询]后 ...
- .Net组件程序设计之异步调用
.Net组件程序设计之异步调用 说到异步调用,在脑海中首先想到就是BeginInvoke(),在一些常用对象中我们也会常常见到Invoke()和BeginInvoke(), 要想让自己的组件可以被客户 ...
- winform异步进度条LongTime
winform异步进度条LongTime,运用到回调函数 定义事件的参数类: namespace LongTime.Business { // 定义事件的参数类 public class ValueE ...
- NET中级课--浅谈委托,事件,异步调用,回调等概念
直接说题. 委托 首先明确它是什么,其实就是一个类,定义一个委托即定义一个类,那么它是什么类?用来说明方法的类型的类.字段有类型,那么方法其实也有类型,就是委托. 委托是某 ...
- C# 委托高级应用----线程——创建无阻塞的异步调用(一)
前言 本文大部分内容来自于mikeperetz的Asynchronous Method Invocation及本人的一些个人体会所得,希望对你有所帮助.原英文文献可以在codeproject中搜索到. ...
- 谈.Net委托与线程——创建无阻塞的异步调用(一)
前言 本文大部分内容来自于mikeperetz的Asynchronous Method Invocation及本人的一些个人体会所得,希望对你有所帮助.原英文文献可以在codeproject中搜索到. ...
随机推荐
- (1)搜索广告CTR预估
https://www.cnblogs.com/futurehau/p/6181008.html 一.广告投放系统 广告系统包含多个子系统.除了上图所示的广告投放系统外,还包含商业系统(广告库的获得) ...
- python合并多个txt文件成为一个文件
#coding=utf-8 import os import os.path #文件夹遍历函数 #获取目标文件夹的路径 filedir = './data/click_data' #获取当前文件夹中的 ...
- vue跨域问题解决(生产环境)
vue跨域问题解决(使用webpack打包的) 配置代理:(config下index.js文件) module.exports = { dev: { env: require('./dev.env') ...
- Node.js之错误处理
Node.js之错误处理 1. 使用 domain 模块处理错误 try..catch 多用于捕捉同步方法中的抛出错误,但不能用try..catch捕捉异步方法中抛出de错误 如: 1 var htt ...
- Nginx不转发http header
使用nginx做http代理时,在Header中使用了一个名为api_key的属性,碰到http header不转发的问题. 问题源码: rc = ngx_http_parse_header_line ...
- hdu_1005_Number Sequence_201310222120
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- mysql子查询案例
源SQL如下: 创建数据表 CREATE TABLE IF NOT EXISTS tdb_goods( goods_id SMALLINT UNSIGNED PRIMARY KEY AUTO_ ...
- firedac的数据序列和还原单元(Data.FireDACJSONReflect.pas)之拷贝FIREDAC数据集
使用流做中转 procedure CopyDataSet(const ASource, ADest: TFDAdaptedDataSet);var LStream: TStream;begin LSt ...
- [jQuery]ajax请求导致浏览器崩溃
$("#xxx").val() not $("#xxx") 如果忘记加上.val()会导致chrome崩溃
- iOS:解决pod的Insecure world writable dir问题
当我们运行pod setup的命令的时候,有时候会碰到这个警告: /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/lib/cocoapods/execut ...