Good afternoon, it’s actually the time when I need to work with an array of bytes, and I’m not talking about them bye, bye, I studied them briefly, the essence of the issue.

I have an array of 'Data' bytes, and I need to transfer them to 'SendAsync (data.Data, 20);'

If I pass them directly, I get an exception - StackOverflowException.

And as I understand it, I need to create some sort of BlockSize (Or something like this) of the type - var buff = new byte [3840];

This is what SendAsync takes - enter image description here

Actually what should I do?

enter image description here

  • 2
    StackOverflowException arises from a recursive call without checking. Arrays of bytes have nothing to do with it, look for an error elsewhere with the debugger. - VladD

1 answer 1

An array in C # is a memory area preceded by a pointer to the type of the array element and the number of elements.

In SendAsync, you can send anything you want, there are no restrictions. If you get a StackOverflowException error, it means that the memory space allocated for the stack of the current thread is exhausted. The default stack size is 1 MB. If you do not do manual allocation of memory, then with a probability of 98% these are recursive calls. Most often - a call of the same method from itself. Less often - a long chain of recursive calls on a large number of elements (eg, expanding containers on the file system). In this case, the transition to tail recursion will help.

I can assume that, in your case, the MediaDataSent event MediaDataSent routed after sending the data, keeping the context of the calls, thus forming an endless chain of calls. You can check this by uncommenting the line with sending data, getting up in this place in the debugger, and skipping a few iterations. After that, look in the call stack window.