Я использую метод threadpool для многопоточности, в то время как пользовательский интерфейс не знает почему, есть ли какое-то решение для этого.вот фрагмент кода:
private void CommentThread(object obj)
{
CancellationToken token = (CancellationToken)obj;
RandomNumber = new Random();
// ListViewItemCollection URLCOllection;
if (UrlListview.InvokeRequired)
{
UrlListview.Invoke(new MethodInvoker(delegate
{
// URLCOllection = UrlListview.Items;
foreach (ListViewItem item in UrlListview.Items)
{
MessageBox.Show(item.Text);
Thread.Sleep(3000);
}
/*
foreach (ListViewItem url in URLCOllection)
{
if (token.IsCancellationRequested)
{
cts.Cancel();
return;
}
MessageBox.Show(url.Text);
int delayamount = RandomNumber.Next(int.Parse(CommentsMinDelayNumric.Value.ToString()), int.Parse(CommentsMaxDelayNumric.Value.ToString()));
Thread.Sleep(delayamount*1000);
}
}
*/
}));
}
else
{
URLCOllection = UrlListview.Items;
}
foreach (string url in URLCOllection)
{
if (token.IsCancellationRequested)
{
cts.Cancel();
return;
}
MessageBox.Show(url);
int delayAmount = RandomNumber.Next(int.Parse(CommentsMinDelayNumric.Value.ToString()), int.Parse(CommentsMaxDelayNumric.Value.ToString()));
Thread.Sleep(delayAmount * 1000);
}
}