【发布时间】:2015-12-01 04:30:47
【问题描述】:
我的程序:
我创建了 2 个线程:线程 1 带有一个监听套接字,线程 2 做一些事情。
但是线程 1 阻塞了程序,我无法启动线程 2,直到线程 1 上的侦听套接字接收到数据。
但我需要 2 个线程同时运行,并且不需要在 2 个线程之间保持同步。(但仍在同一个程序中)。
怎么做???
我的代码是这样的:
Thread thread1 = new Thread(new ThreadStart(a.thread1));
Thread thread2 = new Thread(new ThreadStart(b.thread2));
try
{
thread1.Start();
thread2.Start();
thread1.Join(); // Join both threads with no timeout
// Run both until done.
thread2.Join();
}
程序在线程 1 处停止(监听套接字)。
而且我不想使用非阻塞套接字(我正在使用阻塞套接字)。
监听套接字应该阻塞子线程,但不应该阻塞我的程序。
【问题讨论】:
标签: c# multithreading sockets asyncsocket