我使用此函數由Stack Overflow用戶來更新來自BackgroundWorker
的控件。InvalidAsynchronousStateException在函數中檢查控件是否需要調用
static void SynchronizedInvoke(ISynchronizeInvoke sync, Action action)
{
// If the invoke is not required, then invoke here and get out.
if (!sync.InvokeRequired)
{
// Execute action.
action();
// Get out.
return;
}
// Marshal to the required thread.
sync.Invoke(action, new object[] { });
}
此功能一直運行良好,直到現在。我剛剛得到這個異常:
這是什麼意思?如何預防呢?
查看https://stackoverflow.com/a/38411886 – SMUsamaShah 2017-12-12 07:25:18