나는 새로운 작업이며, 내가 원하는 방식으로 사용하는 것이 좋은지 정말로 알지 못합니다.다른 스레드에서 개체에 액세스 - 작업
나는 TextBlock에서 상속 받고 텍스트를 색칠합니다 (Syntaxhighlighting). 그것은 여기 내 코드는 지금까지입니다 내가
배경
에서하고 싶지 그래서 좀 걸릴 않습니다async void SyntaxTextBlock_TargetUpdated(object sender, System.Windows.Data.DataTransferEventArgs e)
{
if ((clientSettings.SyntaxCheck || clientSettings.SyntaxHighlighting) && !string.IsNullOrEmpty(Text))
{
string value = Text;
Syntax syntax = await Task.Factory.StartNew(() => DoSyntax(value));
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
if (syntax.IsTextDecoration)
TextDecorations.Add(Syntax.TextDecoration);
ToolTip = string.Join(Environment.NewLine, syntax.Messages);
Text = null;
foreach (Run run in syntax.Runs)
Inlines.Add(run);
}));
}
}
내 문제는 내가 DoSyntax(value)
에 의해 반환되는 객체 Syntax
에서 syntax.Runs
목록에 액세스하지 못할 수 있습니다.
오류 : the calling thread cannot access this object because a different thread owns it
내가 스케줄러 TaskScheduler.FromCurrentSynchronizationContext
와 그것을 시도하고 일하지만, GUI가 얼어 붙었다.
GUI가 고정되지 않은 상태에서 여러 개의 다른 스레드에서이 작업을 수행 할 수 있습니까?
오류는 다음과 유사 할 수 있습니다. http : //stackoverflow.com/questions/9732709/the-calling-thread-cannot-access-this-object-because-a-different-thread-owns-it –
NET에서 다른 스레드간에 공유 목록의 가능한 복제본 (http://stackoverflow.com/questions/4011031/list-shared-between-different-threads-in-net) –
알다시피, 이미 구현했습니다. Dispatcher.Invoke call –