Add an analyzer to force passing TaskSchedulers when creating Tasks.
If you call Task.Factory.StartNew and use one of the overloads that doesn't take TaskScheduler, the resulting task is scheduled onto TaskScheduler.Current. This is very dangerous in a free-threaded library like Roslyn: if the function runs on the UI thread it's possible the resulting Task will be scheduled on the UI thread accidentally. If later UI code were to wait on that task or a continuation of it, we might deadlock. The solution is just to ban the APIs -- if somebody wishes to schedule to the current thread, it's up to them to be explicit. Otherwise, TaskScheduler.Default should be used. (changeset 1407143)
Showing
想要评论请 注册 或 登录