Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Sample/React. Cannot run the process on a background thread #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
st-algernon opened this issue Apr 10, 2023 · 3 comments
Closed

Sample/React. Cannot run the process on a background thread #118

st-algernon opened this issue Apr 10, 2023 · 3 comments

Comments

@st-algernon
Copy link

I ran the Sample/React project and tried to keep the donut from lagging under stress. Enabling CreateWorker didn't work for me :/ After which I saw your comment: "After some testing I've figured worker interaction layer adds too much complexity and makes debugging harder. It'll make more sense and will probably be more performant to use threading on C# side (#79)."

So I tried using Task on C# side.

        public async Task StartStress()
        {
            cts?.Cancel();
            cts = new CancellationTokenSource();
            await Task.Run(() => Stress(cts.Token));
        }

        private async Task Stress(CancellationToken token)
        {
            while (!token.IsCancellationRequested)
            {
                var time = DateTime.Now;
                await Task.Run(() => ComputePrime(frontend.GetStressPower()), token);
                frontend.NotifyStressComplete((DateTime.Now - time).Milliseconds);
                await Task.Delay(1, token);
            }
        }   

I'm not strong in multithreading, but I thought this should work. Understandably, it didn't work

How can I run the process on a background thread? is it possible now? I will be very grateful for the answer

@elringus
Copy link
Owner

It should be possible once multithreading support is implemented on .NET's wasm runtime (#79) and after we move to the stock runtime (#20).

@st-algernon
Copy link
Author

thanks a lot 🤗

@elringus
Copy link
Owner

elringus commented Apr 10, 2023

Running C# backend on worker thread is actually a desirable scenario for my own project, so I'll most likely add an option to serve interop calls via an async queue, so that they can be processed off the main thread by default. If you'd like to future-proof for that usage scenario, make interop APIs async so that later you can just enable the option w/o breaking anything.

Repository owner locked and limited conversation to collaborators Apr 10, 2023
@elringus elringus converted this issue into discussion #119 Apr 10, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants