using
is a very specific keyword in C#, it's used to control teh disposal of items when they ar efinished with.
Writing this:
using (MyClass mc = new MyClass)
{
...
}
Is the equivelant of writing this:
{
MyClass mc;
try
{
mc = new MyClass();
...
}
finally
{
mc.Dispose();
}
When your app reaches the end of the
using
block and
we
goes out of scope is it Disposed automatically - so any open connection is Closed, any delegates are cleared, the memory is returned to the heap, and the WebSocket no longer exists at all.
So it can't receive anything - it isn't open, it doesn't exist, and it doesn't have any handler methods!
Make it a class level
private
variable, and it should start to work.