See Also: StateMachineAttribute Members
You should not apply the StateMachine attribute to methods in your code. For methods that are state machine methods, the compiler will apply the System.Runtime.CompilerServices.AsyncStateMachineAttribute or System.Runtime.CompilerServices.IteratorStateMachineAttribute in the emitted IL.
When checking whether a method is a state machine method, it is preferable to instead check for following attributes, which are derived from StateMachineAttribute:
StateMachineAttribute cannot be used to check whether a method is a state machine method if the method is an iterator method in C#.