c# - Preventing simultaneous calls to a WCF function -
i have wcf service running windows service. service references dll containing class x public method func1. func1 calls method func2(private) asynchronously using tasks(tpl). func2 performs long running task independently. setup :
wcf
public string wcffunc() { x obj = new x(); return obj.func1(); }
dll
public class x { static bool flag; public x() { flag = true; } public string func1() { if (!flag) return "already in action"; task t = null; t = task.factory.startnew(() => func2(),taskcreationoptions.longrunning); return "started"; } void func2() { try { flag = false; //does long running database processing work through .net code } catch (exception) { } { flag = true; } } }
the wcf function called website. website used multiple users. no 2 execution of database processing func2 allowed. user can trigger it. during execution, if other user attempts trigger it, should show processing running. tried use static variable 'flag' check it, not seem working.
any solutions? in advance.
you can read following article, prevent multiple calls wcf service method, need first ensure 1 instances of service can created in addition setting concurrency mode.
in short, make following changes servicebehavior:
[servicebehavior(concurrencymode = concurrencymode.single, instancecontextmode=instancecontextmode.single)] public class yourservice: iyourservice {...}
note : disable concurrency in methods exposed service, if not want have move needed method separate service , configure above.
Comments
Post a Comment