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;
namespace WorkFlow
{
    public partial class Server : Form
    {
        private delegate void FlushClient();//代理
        Thread thread = null;
        int counter = 0;
        public Server()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 加载load事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Server_Load(object sender, EventArgs e)
        {
            thread = new Thread(CrossThreadFlush);
            thread.IsBackground = true;
            thread.Start();
        }
        private void CrossThreadFlush()
        {
            while (true)
            {   //将sleep和无限循环放在等待异步的外面
                Thread.Sleep(1000);
                ThreadFuntion();
            }
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public void ThreadFuntion()
        {
            if (this.dtReadList.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(ThreadFuntion);
                this.Invoke(fc); //通过代理调用刷新方法
            }
            else
            {
                counter += 1;
                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;
            }
        }
    }
}

Winform 异步调用的更多相关文章

  1. 一个简单的webservice的demo(下)winform异步调用webservice

    绕了一大圈,又开始接触winform的项目来了,虽然很小吧.写一个winform的异步调用webservice的demo,还是简单的. 一个简单的Webservice的demo,简单模拟服务 一个简单 ...

  2. Winform 异步调用2 时间

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. 用Html5/CSS3做Winform,一步一步教你搭建CefSharp开发环境(附JavaScript异步调用C#例子,及全部源代码)上

    本文为鸡毛巾原创,原文地址:http://www.cnblogs.com/jimaojin/p/7077131.html,转载请注明 CefSharp说白了就是Chromium浏览器的嵌入式核心,我们 ...

  4. WinForm查询大数据界面假死,使用异步调用解决

    用DataGridView无分页绑定一个几千条数据的查询,查询的时候界面直接卡死十几秒,用户体验非常不好,因此用异步操作解决界面卡死的问题原本场景:点击[查询]后,界面直接卡死优化场景:点击[查询]后 ...

  5. .Net组件程序设计之异步调用

    .Net组件程序设计之异步调用 说到异步调用,在脑海中首先想到就是BeginInvoke(),在一些常用对象中我们也会常常见到Invoke()和BeginInvoke(), 要想让自己的组件可以被客户 ...

  6. winform异步进度条LongTime

    winform异步进度条LongTime,运用到回调函数 定义事件的参数类: namespace LongTime.Business { // 定义事件的参数类 public class ValueE ...

  7. c# 委托与异步调用

    背景:在winform UI中,有时需要对控件进行比较频繁的刷新,如进度条.picturebox显示视频等.如果在主线程进行这些刷新操作,操作还未完成就将执行下一次刷新,程序将发生错误:如果只是创建另 ...

  8. [转]WinForm如何调用Web Service

    1.建立项目WebService和WinForm项目,这里起名为WinFormInvokeWebService,如图所示, 2.Service1.asmx代码为:(这部分其实和上篇的代码是一样的) u ...

  9. C#中运用事件实现异步调用

    问题引出: winform程序中的耗时操作,一般不能在UI线程中执行,需要另开线程.往往我们需要在耗时操作结束后将结果显示在UI上. 以下是Mainform.cs中调用耗时操作的一段代码: Job j ...

随机推荐

  1. adjtimex修改tick值用法举例

    测试 用户态下内核时钟计数间隔,默认都是100HZ.因此单个tick代表了10^4 us. 可以设置每个tick代表的时钟长度,因此把tick增加1(即增加为10001us)的影响是每天时间快8.64 ...

  2. [LUOGU]4932 浏览器

    \(\_\_stdcall\)大佬出的题\(Orz\) 我们惊奇地发现,加入\(\_\_popcount(x)\)和\(\_\_popcount(y)\)的奇偶数性相同,那么\(\_\_popcoun ...

  3. Ajax基本写法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Git 基础教程 之 标签

    所谓标签:就是一个让人容易记住的有意义的名字,与某个commit绑在一起. 创建标签:①切回需要打标签的分支上                  ② git tag <name>  默认标 ...

  5. 腾讯云,搭建 Discuz 个人论坛

    准备 LAMP 环境 任务时间:30min ~ 60min LAMP 是 Linux.Apache.MySQL 和 PHP 的缩写,是 Discuz 论坛系统依赖的基础运行环境.我们先来准备 LAMP ...

  6. 优雅的退出/关闭/重启gunicorn进程

    在工作中,会发现gunicorn启动的web服务,无论怎么使用kill -9 进程号都是无法杀死gunicorn,经过我一番百度和谷歌,发现想要删除gunicorn进程其实很简单. 第一步获取Guni ...

  7. random随机库

    random库是用于产生并运用随机数的标准库 主要包含的有9个随机函数,分别是: seed(), random(), randint(), getrandbits(), randrange(), un ...

  8. 【Codeforces 1106E】Lunar New Year and Red Envelopes

    [链接] 我是链接,点我呀:) [题意] 给你k个红包,每个红包可以在si..ti的时间范围内拿走. 抢完红包之后你得到wi元,然后你需要在di+1时刻才能继续抢红包 时间是线性的从1..n 然后某个 ...

  9. ansible ad-hoc 参考

    # 检查主机连接 # ansible test -m ping # 执行远程命令 # ansible test -m command -a 'uptime' # 执行主控端脚本 # ansible t ...

  10. nyoj_915_+-字符串_201402261520

    +-字符串 时间限制:1000 ms  |           内存限制:65535 KB 难度:1   描述 Shiva得到了两个只有加号和减号的字符串,字串长度相同.Shiva一次可以把一个加号和 ...