컬렉션에 바인딩 된 목록보기가 있습니다.Wpf Dispatcher 일시 중지 및 계속
항목이 목록보기에 점진적으로 추가되도록 dispatcher.current 발송자를 사용하여 모음이 업데이트됩니다.
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
if(continueDispatcher)numDone = DoStuff();
}));
이 정말 잘 작동하고 continueDispatcher 플래그는 멋진 해당 트랙에서 죽은 스레드를 중지,하지만 난 버튼 클릭에 디스패처 작업을 계속 할 수 있도록하고 싶습니다.
디스패처 프레임 등을 읽었지만 작동하는 솔루션을 찾을 수없는 것 같습니다.
아무도이 문제에 대해 아이디어가 있습니까?
편집 - 더 코드
//for each image
foreach (var result in results)
{
result.Type = type;
numDone = LoadImagesAsync(result, numDone, total);
}
private int LoadImagesAsync(Item result, int numDone, int total)
{
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
//keep looping
while (true)
{
//if the dispatcher is paused then continue the loop
if (DispatcherPaused) continue;
//if the dispatcher is not paused then perform the action and break out of the loop
numDone = DoStuff(result, numDone, total);
break;
}
}));
return numDone;
}
private int DoStuff(Item result, int numDone, int total)
{
ItemList.Add(result);
numDone++;
ProgressBarValue = ((double) numDone/total)*100;
return numDone;
}
- C#
- 비주얼 스튜디오 2012
죄송합니다. 귀하가하려는 일을 이해하지 못했습니다. 그리고 그 깃발은 실에있는 실을 어떻게 멈추게합니까 *? – Dirk
무한 루프에 넣지 않는 이유는 무엇입니까? – Bijan
@Bizz 작동하지만 루프가 실행 중일 때 UI를 잠급니다. –