Touseefelahi / GigeVision

Simple GigeVision implementation, GVSP, GVCP protocol implemented
97 stars 31 forks source link

program crashed after receive socket reply #87

Closed YorkWong1995 closed 11 months ago

YorkWong1995 commented 1 year ago

I wanna to got the data in UdpReceiveResult.Result.buffer in SendGvcpCommand function. but When i got reply from socket, and run reply.Result.Buffer != null , it suddenly crashed with no exception. use wireshark there is no any data.
Do u know what will lead to this problem here is my code. cap

thanks in advance.

YorkWong1995 commented 1 year ago

In debug mode , sometimes , reply.Result.buffer is now at first , but when it runs reply.Result.Buffer != null, reply.Result.buffer got data, it is not null any more. and i do not find the reason, too. In this situation, wireshark will get the return package.

YorkWong1995 commented 1 year ago

It seems receiveasync is Asynchronous method so when i want to compare reply.result.buffer with null reply is receiving data, meanwhile , i want to get the reply value to do comparation

Touseefelahi commented 1 year ago

@YorkWong1995 this is not related to the library. You must understand how asynchronous methods work. You must wait for it to finish before doing anything with the result. From this snippet, it seems like you are not using the library properly.

YorkWong1995 commented 1 year ago

I also used if (await Task.WhenAny(reply, Task.Delay(socketTx.Client.ReceiveTimeout)).ConfigureAwait(false) == reply) to wait the method finished. but in debug mode, this condition is never satisfy. the reply status is always waitingforactivation, but wireshark already caught the return package.

In another word, i used var ret = await Task.WhenAny(reply, Task.Delay(socketTx.Client.ReceiveTimeout)).ConfigureAwait(false); the status of ret is always different from the reply‘s

YorkWong1995 commented 1 year ago

After Task reply = socketTx.ReceiveAsync(); I used await reply; ,Sometimes, it will crushed. I used if (await Task.WhenAny(reply, Task.Delay(socketTx.Client.ReceiveTimeout)).ConfigureAwait(false) == reply) ,Sometimes, it also crushed. And i am confused,because wireshark sometimes can get the reply package, when the library crashed .

Touseefelahi commented 1 year ago

can you comment the whole method?

YorkWong1995 commented 11 months ago

This problem is not related to library