【发布时间】:2016-08-18 06:29:34
【问题描述】:
我正在从我通常的 C++ 编程中自学 C#,现在我正在做线程。
以下简单代码编译良好,应该通过线程在循环中输出哔哔声 30 秒。
using System;
using System.Runtime.InteropServices;
using System.Threading;
class BeepSample
{
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool Beep(uint dwFreq, uint dwDuration);
static void Main()
{
Console.WriteLine("Testing PC speaker...");
for (uint i = 100; i <= 20000; i++)
{
var BeepThread = new Thread(delegate() { Beep(i, 30000); });
}
Console.WriteLine("Testing complete.");
Console.ReadLine();
}
}
唯一的问题是线程似乎不起作用。
我知道我缺少一些基本的东西。
有什么想法吗?
【问题讨论】:
-
只要你输入
new Thread(),就结束了;您的项目已经有旧代码。 C# Cookbook 中的并发,@StephenCleary
标签: c# multithreading