RunSynchronously may not be called on a task not bound to a delegate
I have a sync kafka method that interfaces message on kafka, whenever I use it on method I got error called 'RunSynchronously may not be called on a task not bound to a delegate, such as the task returned from an asynchronous method.'
is there anyway to use and make a sure sendKafka Method completes when it is called without changing the implementation of SendKafka method itself?:
18 Replies
hellow
is the context an async contexT?
If its not try this
public void InterfaceUserInformation(IDbContext dbContext, Materiallot materiallot, MessageData messageData)
{
MessageBuilderMD messageBuilderMD = new MessageBuilderMD();
messageBuilderMD
.WithMessageData(messageData)
.WithNameOfRequest("To try")
.Build();
kafkaContext.SendKafka(messageBuilderMD.GetMessageData(), dbContext).GetAwaiter().GetResult();
}
this should work or you can chnage the function too
public async Task InterfaceUserInformationAsync(IDbContext dbContext, Materiallot materiallot, MessageData messageData)
{
MessageBuilderMD messageBuilderMD = new MessageBuilderMD();
messageBuilderMD
.WithMessageData(messageData)
.WithNameOfRequest("To try")
.Build();
// Await the asynchronous SendKafka method
await kafkaContext.SendKafka(messageBuilderMD.GetMessageData(), dbContext);
}
let me know if you have any questionsthis context doesn't have a getAwaiter 😦
its expecting an async output
i will try to see if it builds
Error (active) CS1061 '=Context' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type
Not a task, then
wdm?
Exactly what I said
.GetAwaiter()
is a method of Task
Only a Task
can be await
ed
Ergo, not a taskyeah
what would be a way to use that method?
What do the docs of the library you're using suggest?
well, there is no library the code itself packed into nuget, and I saw a code once,it was using cofluent
What do the docs of the nuget you're using suggest?
There is no documentation on this wrapper sadly
I'd use a wrapper that isn't shit, then
That connect with kafka using cofluent and make producer with consumer..sendkafka a method that produces a message
Well ,I agree
There seems to be a well-documented official library by Confluent: https://docs.confluent.io/kafka-clients/dotnet/current/overview.html
I know, but I need to use exact method
Did you step through the code to see what exactly is throwing here?
Also, the answer to
is there anyway to use and make a sure sendKafka Method completes when it is called without changing the implementation of SendKafka method itself?is "no" You could do it like it's 2001 Javascript and use callbacks like a caveman You could do it properly with async/await But either would require the
SendKafka
method to be changed
Or not written by a halfwit in the first place
Assuming it is supposed to be observed like that and isn't supposed to be just a fire&forgetwell thanks, seems like I need to wait him again