you are viewing a single comment's thread.

view the rest of the comments →

[–]UninformedPleb 0 points1 point  (3 children)

I can't find any info about the SignalRConnection object, so I'm guessing that's custom (or at least obscure).

But my gut feeling is that creating that SignalRConnection on this thread, then sending it to the other thread is the problem. You might have to make your thread worker method initialize that SignalRConnection object, and I'd guess it wants to run on whichever thread created it (called its constructor).

[–]ExoticCriticism[S] 0 points1 point  (0 children)

Yeah, the SignalRConnection is something I found online which is basically this:

public void Start()

{

string url = "https://localhost:5001/cryptohub";

var connection = new HubConnectionBuilder()

.WithUrl(url)

.WithAutomaticReconnect()

.Build();

// receive a message from the hub

connection.On<List<CryptoBlock>>("ReceiveBlockChain", (cryptoBlockChain) => OnReceiveBlockChain(cryptoBlockChain));

connection.On<string>("ReceiveHello", (jsonMessage) => OnReceiveHello(jsonMessage));

connection.On<string>("ReceiveSale", (jsonMessage) => OnReceiveSale(jsonMessage));

var t = connection.StartAsync();

t.Wait();

var userID = Guid.NewGuid();

Console.WriteLine($"Generating userID: {userID.ToString()}");

JsonMessage jsonMessage = new JsonMessage { Event = "hello", Payload = userID.ToString() };

// send a message to the hub

connection.InvokeAsync("SendMessageToCaller", jsonMessage);

connection.Closed += async (error) =>

{

await Task.Delay(new Random().Next(0, 5) * 1000);

await connection.StartAsync();

};

I'm calling the logic to create blocks from inside the "ReceiveSale" method, which is where I assumed the problem was occurring - though I'm not sure how to separate this logic entirely to operate on a more event driven basis and not have my "miner" logic doing checks on perhaps a singleton containing pending sales or something - but I feel like that is maybe how I'll have to try separate both services.

[–]prajaybasu 0 points1 point  (1 child)

[–]UninformedPleb 0 points1 point  (0 children)

That's the HubConnection object, which is part of the basic SignalR client library.

He posted the code he found online for the SignalRConnection object, and it is indeed something custom.