C# - passing in a boolean that might change elsewhere, but I don't want to change in the method -


i have method needs react iscanceling flag. should able changed elsewhere , noticed within method, don't want able change boolean within method. have below, think able read bool if passed in boolean changed elsewhere, want ensure iscanceling cannot changed within context. possible?

public static bool dosomething(ref bool iscanceling) {     while(whileloopflag && !iscanceling)     {         //dothething()     } } 

use cancellationtokensource/cancellationtoken allow code external method cancel it. in addition having api object can notify of cancellation, synchronize underlying boolean such objects can used multiple threads without problems.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -