Comments (13)
ThreadPool.BindToHandle
only allows a handle to be bound once per thread. It appears you're trying to reuse the handle held in device
in your code. So my question is: Should the library work around the ThreadPool
code or are you using DeviceIoControl
in a way that is not consistent with its pattern by calling it twice? I'm not familiar enough with that function to answer the question.
from vanara.
Reuse device
is common scenes, for example: open a virtual network adapter, and then keep reading and writing in a while loop for redirect or analysis network traffic. If open and close device frequently, it will reduce performance.
Even the example is Read
and Write
, but this depends on the driver implementation, if it implement by DeviceIoControl ?
from vanara.
This one also is ready for testing
from vanara.
Capturing exceptions can cause some performance degradation.
So, I don't think so BindHandle
each call is a good way.
Please see my test result:
This is the last code without my fix, you can see I call DeviceIoControlAsync
100 times, and print it cost time in Milliseconds:
the result:
If I do some fix, only BindHandle
at first time, and the test code do not change as above:
the result:
from vanara.
I came up with three compromises.
-
Wrap
CreateFile
withbool isAsync
argument,BindHandle
in sideCreateFile
ifisAsync == true
. Or check ifFileFlagsAndAttributes.FILE_FLAG_OVERLAPPED
had set. -
Exposing
bool bindHandle
argument for all the paths ofDeviceIoControlAsync
, but there's too much codes to modify, and it's not very elegant. -
Remove
BindHandle
that is insideSetupOverlappedFunction
and add checking if thedevice
had bind. Throw an exception tells user need to bind handle manually if not bind. (I don't know if this is feasible)
from vanara.
I had thought about 1 and 3. The problem is that the ThreadPool uses the handle to associate threads so it is not copying handles across thread boundaries. Removing it reduces the threading performance. I can collect handles and check them before calling BindHandle. With that, I only run the risk of holding the handle value until the process terminates. Maybe ThreadPool is already doing this so there is no harm.
from vanara.
Do you means save handles in a static HashSet
or Dictionary
, and check is it already exist before bind ?
from vanara.
Exactly
from vanara.
It seems feasible.
from vanara.
I just pushed updated code. Let me know if the bug is gone and performance is back.
from vanara.
Works well now.
from vanara.
By the way, are you planning to release version 2.3.0 of the nuget package these days ?
from vanara.
Yes. In the next 2 days.
from vanara.
Related Issues (20)
- False-positive `IsNullOrEmpty` on `StrPtrAuto` HOT 1
- Wrong marshalling for pszVerb in Shell32.IFolderView2.InvokeVerbOnSelection() HOT 1
- The file generated by ShellLink.Create() is not a shortcut file. HOT 1
- Dotnet 5 Error HOT 7
- SafeHANDLE != operator should make parameters nullable HOT 3
- WinINet.InternetSetOption seems breaking change in 4.0.0 HOT 1
- CRYPT_PROVIDER_DATA duplicates CRYPT_PROVUI_DATA HOT 1
- System.TypeInitializationException: The type initializer for '<Module>' threw an exception. HOT 1
- DOSvc unit test fails with 0x80010123 HOT 2
- Unable to create TXT records HOT 3
- ErrorHelper.GetErrorMessage throws System.OverflowException HOT 1
- ContextMenu related problems HOT 1
- Add a function to enumerate all open Windows Explorer Instances, including the path that is selected
- Problems using WlanGetNetworkBssList of the WLAN API HOT 3
- Custom marshalers cannot be used on fields of structures. HOT 1
- IpHlpApi.GetAdaptersAddresses() GatewayAddresses Member is always zero HOT 3
- The Portable Device API uses HRESULT return values for their methods HOT 3
- Vanara.Windows.Shell throws COMException when enumerating special items (WinAppSDK 1.5) HOT 10
- FwpUClnt.FWPM_FILTER0.filterId is broken HOT 1
- Kernel32 GetProcAddress for 64its HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vanara.