c# - Brokering IO requests in a static class -
I have a single, static broker
class with a group of 'drivers' The network IO that creates the request for the tool I have examples of a device
class that tells the device to read the data through the drivers.
The broker is present to meet the requests of other sections because we have a limited number of concurrent connections which we can do.
The problem occurs when devices
share the same driver type and make overlapping calls for data. Driver is a shared resource and both can not serve at the same time.
Here is a meaningful implementation (not running, how do I just do it):
Obviously, if two devices call with the same driver, then there is no mechanism for 'queue' to request.
Does anyone have any idea how can I wait for the call to the calling client for the data?
You can probably use it for:
static reading For s_semaphore = new semaphorcil (1); Public stable async works & lt; IList & lt; Ushort & gt; & Gt; ReadDataItem (Driver Type Driver Type, String IP, Data IT Address Address, Action & LT; IELIT & UT Left; gt; & gt; Callback) {{driver = Recovery Driver (Driver Type)) using {if (Driver! ) {// Note: Make sure the connection is set to correct PLC) // You can use different semaphores, // await s_semaphore.WaitAsync () based on the type of driver; Try {return ask ask.Factory.StartNew (() => driver.readDataItem (address)); } Finally {s_semaphore.Release (); }}}
Comments
Post a Comment