Share via

ClientWebSocket method throw new InvalidOperationException(SR.GetString(SR.net_WebSockets_AlreadyStarted))

2022-08-09T02:59:03.56+00:00

hi all!
In thread method, using System.Net.WebSockets.ClientWebSocket class method ConnectAsync, but sometimes throw exception like this " new InvalidOperationException(SR.GetString(SR.net_WebSockets_AlreadyStarted))", sometimes is ok, can you help me ?

some code as follows:
try
{
ConnectAsync(new Uri(_url), new CancellationToken()).Wait()
}
catch (Exception ex)
{
....... // here, new InvalidOperationException(SR.GetString(SR.net_WebSockets_AlreadyStarted))
}

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.