http://topic.csdn.net/u/20080429/09/9cfe5204-20b5-40fb-ac12-afdc1e4939e9.html?590511460
线程终止问题
http://blog.csdn.net/wuyazhe/article/details/1771470
带有消息机制的线程 - CustomMessageQueue(c#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace CustomMessageQueue_CSharp
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private CustomMessageQueue myMsgQueue;private bool CustomMessageProc(ref CustomMessage m){if (m.Message == 1){MessageBox.Show("我拦截到 id = 1 的消息了。并且,就到此为止了。呵呵");return true;}else{MessageBox.Show(m.Message.ToString());}return false;}private void Button1_Click(object sender, EventArgs e){CustomMessage msg = new CustomMessage();msg.Message = 1;msg.param = "我的自定义消息 ID:1";CustomMessageQueue.PostMessage(ref myMsgQueue, ref msg);}private void Button2_Click(object sender, EventArgs e){CustomMessage msg = new CustomMessage();msg.Message = 2;myMsgQueue.PostMessage(ref msg);}private void Form1_Load(object sender, EventArgs e){myMsgQueue = new CustomMessageQueue();myMsgQueue.StartThread();myMsgQueue.PerTranslateMessage = new CustomMessageQueue.PerTranslateMessageHandler(CustomMessageProc);}private void Form1_FormClosing(object sender, FormClosingEventArgs e){myMsgQueue.PostQuitMessage();}}自定义消息队列线程
}
上面是完整的一个程序,包括调用和实现。如果自己使用,可以创建个新的c#工程,添加2个按钮,复制代码即可。