Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

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

You must be logged in to vote

Replies: 3 comments

Comment options

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

You must be logged in to vote
0 replies
Comment options

thanks a lot 🤗

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #118 on April 10, 2023 13:22.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.