摘要: private void button1_Click(object sender, EventArgs e) { //MyMethod my = method; //IAsyncResult asyncResult = my.BeginInvoke(MethodCompleted, my); //Visible控件属性 while (Visible) { for (int rgb = 0; rgb < 254 && Visible; rgb+... 阅读全文
posted @ 2013-02-09 23:11 louiskoo 阅读(736) 评论(0) 推荐(0) 编辑
摘要: BeginInvoke需要加委托才能行,否则会出错,给你段代码参考以下:BeginInvoke 所调用的委托根本就是在 UI 线程中执行的BeginInvoke实现了事件的异步执行,如实例: private static int newTask(int mms) { Console.WriteLine("任务开始"); Thread.Sleep(mms); Random random = new Random(); int n = random.Next(10000); ... 阅读全文
posted @ 2013-02-09 23:00 louiskoo 阅读(326) 评论(0) 推荐(0) 编辑
摘要: 一、C#线程概述在操作系统中一个进程至少要包含一个线程,然后,在某些时候需要在同一个进程中同时执行多项任务,或是为了提供程序的性能,将要执行的任务分解成多个子任务执行。这就需要在同一个进程中开启多个线程。我们使用C#编写一个应用程序(控制台或桌面程序都可以),然后运行这个程序,并打开windows任务管理器,这时我们就会看到这个应用程序中所含有的线程数,如下图所示。如果任务管理器没有“线程数”列,可以【查看】>【选择列】来显示“线程计数”列。从上图可以看出,几乎所有的进程都拥有两个以上的线程。从而可以看出,线程是提供应用程序性能的重要手段之一,尤其在多核CPU的机器上尤为明显。二、用委托 阅读全文
posted @ 2013-02-09 19:37 louiskoo 阅读(246) 评论(0) 推荐(0) 编辑
摘要: 问题:为什么c#中要有ref和out?(而java中没有) 需求假设:现需要通过一个叫Swap的方法交换a,b两个变量的值。交换前a=1,b=2,断言:交换后a=2,b=1。现编码如下:class Program{ static void Main(string[] args) { int a = 1; int b = 2; Console.WriteLine("交换前\ta={0}\tb={1}\t",a,b); Swap(ref a,ref b); Consol... 阅读全文
posted @ 2013-02-09 18:20 louiskoo 阅读(290) 评论(0) 推荐(0) 编辑
摘要: User:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net.Sockets;using System.IO;namespace AsyncTcpServer{ class User { public TcpClient client { get; private set; } public BinaryReader br { get; private set; } public BinaryWr... 阅读全文
posted @ 2013-02-09 17:34 louiskoo 阅读(2436) 评论(0) 推荐(2) 编辑