Thank you very much. I was thinking about returning data from the calculations to the main thread, but the problem is that there's too much data to handle, so I was afraid that memory consumption will be unacceptably high. Now I think I'll manage it.

Thanks again, you saved me from many hours of attempts to walk through a brick wall.