'Trying to not freeze UI using async / await
I am trying not to freeze UI.
I used async / await, but it occurs InvalidOperationException, other thread owned this function. (I translated in english so it might be strange sentence)
public async void MimSetHeight(int _id, double _value)
{
int index;
index = Mim.FindIndex(mim => mim.ID == _id);
if(mim.Count > index)
{
mim[index].ShapeHeight = _value;
await Task.Delay(1000);
mim[index].Shape.Height = _value; // <- Exception occurs
}
}
switch(receivePacket.Data[1])
{
case 53:
Application.Current.Dispatcher.Invoke( () =>
mim.MimSetHeight(5, Convert.ToInt32(Encoding.Default.GetString(receivePacket.Data))));
})));
}
I am feeling i should use Dispatcher.Invoke in last sentence.
Are there any other solution?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
