private void cmbPlatform_SelectedIndexChanged(object sender, EventArgs e)
{
string platform = cmbPlatform.Text;
UpcomingGameFinder gameFinder = new UpcomingGameFinder();
Task.Factory.StartNew<IEnumerable<Game>>(() => gameFinder.FindUpcomingGamesByPlatform(platform))
.ContinueWith((i) => PlaceGameItemsInPanel(i.Result));
}
private void PlaceGameItemsInPanel(IEnumerable<Game> games)
{
int yPosition = 0;
foreach (var game in games)
{
GameItem item = new GameItem(game);
item.Location = new Point(0, yPosition);
panelGameItemsHolder.Controls.Add(item);
yPosition += 125;
}
}
당연히 나는 여기에서 뭔가 잘못하고 있습니다. 내 생각은 Tasks에서 꽤 새로운 것입니다. 따라서이 문맥에서 어떻게 작동할지는 모르겠습니다.이 컨텍스트에서 작업을 어떻게 사용할 수 있습니까?
기본적으로 FindUpcomingGames()는 완료하는 데 오랜 시간이 걸리므로 해당 메서드에서 반환 된 컬렉션을 가져 와서 N 개의 GameItem 개체 (사용자 정의 컨트롤)를 만들고 여기에있는 패널에 배치합니다. Windows Forms.
내가이 오류 메시지가 얻을 :
크로스 스레드 작업을 유효하지 : 제어 'panelGameItemsHolder'가에 만들어진 스레드가 아닌 다른 스레드에서 액세스 .
의견이 있으십니까?
에서 확인할 수 있습니다. 현재이 문제는 현재 무엇입니까? 그것은 컴파일되지 않거나 올바른 결과를주지 못합니까? – Tejs
@Tejs : 더 많은 정보로 편집하겠습니다. :) –