This is a common problem with people getting started. Whenever you update your UI elements from a thread other than the main thread, you need to use:
this.Dispatcher.Invoke(() => { ...// your code here. });
You can also use control.Dispatcher.CheckAccess()
to check whether the current thread owns the control. If it does own it, your code looks as normal. Otherwise, use above pattern.
Related Posts:
- How to use WPF Background Worker
- WFP Grid: MouseRightButtonDown firing occuring BEFORE SelectionChanged on grid. Causing syncing issue
- XAML Binding Groups
- Metadata file ‘.dll’ could not be found
- How to resolve this System.IO.FileNotFoundException
- How to resolve this System.IO.FileNotFoundException
- MSHTML DLL on Windows 10
- MSHTML DLL on Windows 10
- Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on
- How to add comments into a Xaml file in WPF?
- The calling thread must be STA, because many UI components require this in WPF
- WSACancelBlockingCall exception
- Task vs Thread differences
- How can I wait for a thread to finish with .NET?
- How can I get the active screen dimensions?
- Page vs Window in WPF?
- How do I exit a WPF application programmatically?
- How to avoid a System.Runtime.InteropServices.COMException?
- Using FolderBrowserDialog in WPF application
- How can I parse JSON with C#?
- What is IP address ‘::1’?
- What is the yield keyword used for in C#?
- Join/Where with LINQ and Lambda
- C# compiler error: “not all code paths return a value”
- C# equivalent of C++ map
- The page was not displayed because the request entity is too large on IIS
- Export Pervasive to MySQL (C#)
- Why use the params keyword?
- What does plus equals(+=) operator means here?
- The request was aborted: Could not create SSL/TLS secure channel
- finding the maximum length of lists in c#
- The located assembly’s manifest definition does not match the assembly reference
- LEFT OUTER JOIN in LINQ
- OnTriggerEnter not working at Unity3D
- The requested resource does not support HTTP method ‘GET’
- How can I find a specific element in a List
? - Rename a file in C#
- What does mscorlib stand for?
- What is the best way to iterate over a dictionary?
- What is and how to fix System.TypeInitializationException error?
- How to move 2D Object with WASD in Unity
- The Object you want to instantiate is null. Unity 3D
- Convert date yyyyMMdd to system.datetime format
- How to bind a model to a kendo Combobox in order to use the models validatation?
- HttpWebRequest-The remote server returned an error: (400) Bad Request
- Adding values to a C# array
- Adding values to a C# array
- What does {0} mean when found in a string in C#?
- Unity – Gameobject look at mouse
- What does the @ symbol before a variable name mean in C#?
- What is the C# version of VB.net’s InputDialog?
- The entity type ApplicationUser is not part of the model for the current context
- Why did I get the compile error “Use of unassigned local variable”?
- Reading CSV file and storing values into an array
- ASP.NET MVC Page Won’t Load and says “The resource cannot be found”
- How to easily initialize a list of Tuples?
- How do I target @Model within a src of an image tag?
- How to round up in c#
- Converting from IEnumerable to List
- Escape double quotes in a string
- How to do constructor chaining in C#
- What represents a double in sql server?
- How do you get the index of the current iteration of a foreach loop?
- Expression denotes a `type’, where a `variable’, `value’ or `method group’ was expected UNITY3D
- How do I restart my C# WinForm Application?
- Padding is invalid and cannot be removed?
- An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode
- Why is it that “No HTTP resource was found that matches the request URI” here?
- How to split() a delimited string to a List
- Remove element of a regular array
- Best way to reverse a string
- C# Foreach statement does not contain public definition for GetEnumerator
- How do I exit a foreach loop in C#?
- Fastest way to remove first char in a String
- How to convert datetime format to date format in crystal report using C#?
- Most efficient way to remove special characters from string
- When do we use ANTLR
- How would you count occurrences of a string (actually a char) within a string?
- Rotate object in Unity 3D
- C# equivalent to Java’s charAt()?
- How to play a sound in C#, .NET
- Convert SQL to LINQ Query
- How to resolve file being used by another process?
- How to crop an image using C#?
- c# .net change label text
- Check if a string is a palindrome
- Authorization has been denied for this request – New Web API Project
- How do you wait for input on the same Console.WriteLine() line?
- Why doesn’t C# have header files? Will the namespace take care of everything?
- Define: What is a HashSet?
- Convert string to decimal, keeping fractions
- Format of the initialization string does not conform to specification starting at index 0
- How can I generate random alphanumeric strings?
- How do you do a deep copy of an object in .NET?
- Get local IP address
- Delay function in C#
- Cannot declare instance members in a static class in C#
- Error: “an object reference is required for the non-static field, method or property…” [duplicate]
- How to convert HTML to PDF using iTextSharp
- Linq: GroupBy, Sum and Count