I’m writing a multi-threaded applicaiton in C#, VS2008. I used this code to change an element which was created using another thread:
m_OwnerPump.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
m_OwnerPump.Name = textBoxPumpName.Text;
m_OwnerPump.Numbers = numbers.ToArray<string>();
//m_OwnerPump.City = tempInfo.City;
m_OwnerPump.EnergyConsumed = power;
}));
It used to work peacefully but I don’t know why this exception is thrown all of a sudden!
I just played around with the code, to finally found the problem. I don’t know what’s the exact reason, but it’s now working.
The problem was with asking for another control’s property inside the invoker, so I put the property value in a string and used it in the invoker and the final code piece is: