Robert
Robert
CC#
Created by Robert on 1/16/2025 in #help
Task.Run() in .net framework
Thank you!
4 replies
CC#
Created by Robert on 11/20/2024 in #help
Signalr
And the reason i "decided" on signalr is for the auto scalability which is needed
5 replies
CC#
Created by Robert on 11/20/2024 in #help
Signalr
Am I approaching the problem wrong? My goal is to send messages back and forth in a fast way
5 replies
CC#
Created by Robert on 11/20/2024 in #help
Signalr
I have the azure function running locally on 7104, and the 2 webapis are discoverable through public webtunnels. Negotiation works fine
[2024-11-20T11:11:26.291Z] Executing 'Functions.negotiate' (Reason='This function was programmatically called via the host APIs.', Id=3fb28b70-9442-4792-9d63-8d1f33c04f56) [2024-11-20T11:11:26.321Z] C# HTTP trigger function processed a request. [2024-11-20T11:11:26.324Z] Executed 'Functions.negotiate' (Succeeded, Id=3fb28b70-9442-4792-9d63-8d1f33c04f56, Duration=33ms) [2024-11-20T11:20:27.626Z] Executing 'Functions.negotiate' (Reason='This function was programmatically called via the host APIs.', Id=c3fd10f6-9d87-4a4c-b82b-8fcca120ebbc) [2024-11-20T11:21:43.723Z] C# HTTP trigger function processed a request. [2024-11-20T11:21:43.730Z] Executed 'Functions.negotiate' (Succeeded, Id=c3fd10f6-9d87-4a4c-b82b-8fcca120ebbc, Duration=76104ms)
[2024-11-20T11:11:26.291Z] Executing 'Functions.negotiate' (Reason='This function was programmatically called via the host APIs.', Id=3fb28b70-9442-4792-9d63-8d1f33c04f56) [2024-11-20T11:11:26.321Z] C# HTTP trigger function processed a request. [2024-11-20T11:11:26.324Z] Executed 'Functions.negotiate' (Succeeded, Id=3fb28b70-9442-4792-9d63-8d1f33c04f56, Duration=33ms) [2024-11-20T11:20:27.626Z] Executing 'Functions.negotiate' (Reason='This function was programmatically called via the host APIs.', Id=c3fd10f6-9d87-4a4c-b82b-8fcca120ebbc) [2024-11-20T11:21:43.723Z] C# HTTP trigger function processed a request. [2024-11-20T11:21:43.730Z] Executed 'Functions.negotiate' (Succeeded, Id=c3fd10f6-9d87-4a4c-b82b-8fcca120ebbc, Duration=76104ms)
but any other method invoked from the client to server just doesn't work
5 replies
CC#
Created by Robert on 11/20/2024 in #help
Signalr
Here's the Program.cs ( i use the isolated worker as in-process will be deprecated)
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using DotnetIsolated_ClassBased;

var host = new HostBuilder()
.ConfigureFunctionsWebApplication(b => b.Services
.AddServerlessHub<Functions>())
.Build();

host.Run();
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using DotnetIsolated_ClassBased;

var host = new HostBuilder()
.ConfigureFunctionsWebApplication(b => b.Services
.AddServerlessHub<Functions>())
.Build();

host.Run();
Here is the sample webapi
using Microsoft.AspNetCore.SignalR.Client;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

var connection = new HubConnectionBuilder()
.WithUrl("http://localhost:7104/api/", (options) =>
{
options.Headers.Add("UserId", "Sal");
})
.Build();

connection.On<string>("Broadcast", Console.WriteLine);
await connection.StartAsync();
await connection.SendAsync("Broadcast", "This is a broadcast");

app.UseHttpsRedirection();
app.Run();
using Microsoft.AspNetCore.SignalR.Client;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

var connection = new HubConnectionBuilder()
.WithUrl("http://localhost:7104/api/", (options) =>
{
options.Headers.Add("UserId", "Sal");
})
.Build();

connection.On<string>("Broadcast", Console.WriteLine);
await connection.StartAsync();
await connection.SendAsync("Broadcast", "This is a broadcast");

app.UseHttpsRedirection();
app.Run();
5 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
Thank you! I'll have a try
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
forgot to mention .net framework not .net core :(, but I got the idea even without await foreach (such a cool feature btw)
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
and this will effectively be a long running task? or when does the json gets consumed?
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
so that's why we are trying sort of to replicate this with redis
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
We have previously used azure service bus for this, but we have reached to a point where we have more requests than it could handle
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
Yes, I want to immediately continue - sort of a fire and forget, however it happens that MySyncMethod is reached again before the previous SendToRedisCache is finished, is there a way to guarantee that SendToRedisCache2 will finish after SendToRedisCache1 has finished?
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
SendToRedisCache SendToAppendblob are indeed async, but if you're not awaiting them, aren't they run synchronously?
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
without task.run
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
But how do I delegate this work on other threads so I don't block this one?
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
So using this pattern, I face this problem I have a sync method (which i cannot change) that needs to achieve this 2 things: create a json and send it to 2 places (1. to a redis cache, 2. to an appendblbo) I do not wish to block the main thread for this so Task.Run would be used.
public void MySyncMethod()
{
var json = CreateJson();
Task.Run( async () => await SendToRedisCache(json));
Task.Run( async () => await SendToAppendblob(json));
}
public void MySyncMethod()
{
var json = CreateJson();
Task.Run( async () => await SendToRedisCache(json));
Task.Run( async () => await SendToAppendblob(json));
}
The issue I have is that my order of completion is not guaranteed, what mechanism or pattern should I use to guarantee the order of caching and sending to an append blob? I have thought of using 2 concurrent queues (one for caching, one for uploading the append blob, as they are independent of each other) with long-running tasks, but I read it is not ideal, any ideas? So essentially the same problem, how do I wait in the SendToRedisCache for the previous SendToRedisCache to finish before starting?
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
If we make the delegates async, they will be scheduled on the threadpool rather than on the same thread, right?
public async Task TestTasks()
{
List<Func<Task>> tasks = new()
{
async () => await TestAsync("1"),
async () => await TestAsync("2"),
async () => await TestAsync("3"),
};

foreach (var t in tasks)
{
await t();
}
}
public async Task TestTasks()
{
List<Func<Task>> tasks = new()
{
async () => await TestAsync("1"),
async () => await TestAsync("2"),
async () => await TestAsync("3"),
};

foreach (var t in tasks)
{
await t();
}
}
List<Func<Task>> tasks = new()
{
() => TestAsync("1"),
() => TestAsync("2"),
() => TestAsync("3"),
};

foreach (var t in tasks)
{
await t();
}
List<Func<Task>> tasks = new()
{
() => TestAsync("1"),
() => TestAsync("2"),
() => TestAsync("3"),
};

foreach (var t in tasks)
{
await t();
}
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
Thank you for your help!
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
Thank you! This is what I wanted. I don't really get why the latter doesn't start the task automatically?
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
the real application is that i have a stream of messages that i want to cache and write into the db. I want to wait until the previous message has been cached to cache the next one (as the order matters) and I don't want to block the main thread
46 replies
CC#
Created by Robert on 8/8/2024 in #help
Skill issue serializing tasks
No description
46 replies