Comments (3)
... needed to add
catch(Exception ex) {
// Other exception
}
to line 91 of Discovery.cs
from onvif-discovery.
Hello @ispysoftware, Thanks for reporting the issue. Can I know in which OS and target runtime is running the .netstandard library? I could not reproduce it. Did you reproduce it constantly? or some of the times? just to know if some sort of a race condition between the udpClient.Close() and udpClient.ReceiveAsync(). Also I need the Exception Type is it a ObjectDisposedException or SocketException
You need to add the following to make it working?
} finally {
try {
client.Close ();
} catch {
// socket close failed
}
}
or the following?
} catch (OperationCanceledException) {
// Either the user canceled the action or the timeout has fired
} catch (Exception) {
// ReceiveAsync failed
} finally {
client.Close ();
}
But yeah this can happen because UdpClient.ReceiveAsync does not have a CancellationToken, so what I do is the following:
/// <summary>
/// Used to provide cancellation possibility to any Async Methods returning a Task
/// </summary>
internal static async Task<T> WithCancellation<T> (this Task<T> task, CancellationToken cancellationToken)
{
var tcs = new TaskCompletionSource<bool> ();
using (cancellationToken.Register (s => ((TaskCompletionSource<bool>)s).TrySetResult (true), tcs)) {
if (task != await Task.WhenAny (task, tcs.Task)) {
throw new OperationCanceledException (cancellationToken);
}
}
return await task;
}
This just returns when the initial task (ReceiveAsync) finishes or the cancellationToken is cancelled, but in fact the ReceiveAsync is still executing...
I will investigate if there is a better solution to manage the cancellation of the opened Udp socket.
from onvif-discovery.
it was working for ages but then one of my cameras started malfunctioning and closing the request which triggered the exception in the library so reproducing it is hard unless you build a virtual client that just closes the response. Until I rebooted the camera it was happening on every run of the discovery code.
Running on Windows 10, .Net Framework 4.7
adding the catch-all case after OperationCanceledException "fixed" it.
from onvif-discovery.
Related Issues (11)
- Return devices as they reply HOT 4
- Update 5.02 Core
- Duplicate and wrong Model, Manufacturer name HOT 6
- datetime get and set HOT 1
- Not Discovering the Device often HOT 1
- crash when discovery HOT 1
- Detect ONVIF MessageVersion HOT 2
- UdpClientFactory filters to ethernet devices only HOT 2
- How to use in android HOT 1
- Quick Start Guide? HOT 2
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 onvif-discovery.