【发布时间】:2014-01-21 12:26:32
【问题描述】:
我在这段代码中使用了信号量
static Semaphore s = new Semaphore(1,1);
private void button2_Click(object sender, EventArgs e)
{
Thread[] t = new Thread[full_list];
for(int i=0;i<full_list;i++)
{
if (sorted_list[i].audio_node != null)
if (sorted_list[i].audio_node.Checked == true)
{
t[i] = new Thread(DownloadFile);
t[i].Start(sorted_list[i]);
}
}
}
private void DownloadFile(object a)
{
s.WaitOne();
if (InvokeRequired)
{
BeginInvoke(new DownloadFileDelegate(DownloadFile),new object[1] {a} );
return;
}
else
{
download process....
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
s.Release();
}
但它不起作用,我的程序冻结了。我正在尝试解决这个问题,但我不知道为什么它不适用于 Semaphore。所有组件包括下载工作正常。
【问题讨论】:
标签: c# download synchronization semaphore