
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 1.30 KB | hits: 16 | expires: Never
The calling thread cannot access this object because a different thread owns it
drawThread = new Thread(new ThreadStart(drawPosters));
drawThread.SetApartmentState(ApartmentState.STA);
drawThread.Start();
while (true)
{
waitEvent.WaitOne();
//do some calculations
// change uniform grid rows & cols
posterUniformGrid.Rows = calculatedRows; //**-> error is first thrown here**
posterUniformGird.Columns = calculatedCols;
}
Dispatcher.Invoke(DispatcherPriority.Normal,
new Action<object[]>(SetGrid),
new object[] { calculatedRows, calculatedColumns });
while (true)
{
waitEvent.WaitOne();
this.InvokeEx(t => t.posterUniformGrid.Rows = calculatedRows);
this.InvokeEx(t => t.posterUniformGird.Columns = calculatedCols);
}
public static class ISynchronizeInvokeExtensions
{
public static void InvokeEx<T>(this T @this, Action<T> action) where T : ISynchronizeInvoke
{
if (@this.InvokeRequired)
{
try
{
@this.Invoke(action, new object[] { @this });
}
catch { }
}
else
{
action(@this);
}
}
}