Access to disposed closure in C#?

后端 未结 3 1516
谎友^
谎友^ 2020-12-03 16:29

I\'m investigating Microsoft enterprise library (data application block) -- The samples sln.

They have a sample of reading data asynchronously ( IA

3条回答
  •  抹茶落季
    2020-12-03 17:25

    The reason you see ReSharper's warnings is that ReSharper's code flow analysis engine is not strong enough to see what is going on: they assume that your code could get to the end of the using clause without doneWaitingEvent being set, which is not possible due to a while loop:

    while (!doneWaitingEvent.WaitOne(1000)) {
        Console.Write("Waiting... ");
    }
    

    The loop will keep printing the "Waiting... " line until doneWaitingEvent.Set(); gets called, preventing your code from reaching the end of the using block. Same goes for the other warning.

    Long story short, this warning can be safely ignored. Add ReSharper's "ignore this warning" comments, and optionally file a bug report with them.

提交回复
热议问题