Click here to Skip to main content
15,906,708 members

Comments by Ashish Singh Feb2022 (Top 8 by date)

Ashish Singh Feb2022 27-Feb-22 4:09am View    
Its hard to debug service especially with sockets, I created a simple test program with async/await method implementation to test the concept and it looks like it works.
I know you've provided Cancellation example but I'm condfused how would I implement that in a service application.
Ashish Singh Feb2022 25-Feb-22 19:58pm View    
Ok. I'm going through your videos right now.
Ashish Singh Feb2022 25-Feb-22 19:29pm View    
Good morning.

ListenForStatus is already on its own thread spun up from service OnStart method. Why do I need to make it async. And yes, there is loop inside ListenForStatus that just waits for the service to stop

private void ListenForStatus(){    ...    while (!_shutdownEvent.WaitOne(0))    {        ....        ProcessEventAsync(stringData);    }}

Isn't it the ProcessEvent that needs to be async as I need Task.Delay there?

private async Task ProcessEventAsync(string Status){    ...    await Task.Delay(TimeSpan.FromSeconds(30));    //Do something}


Also, how do I handle Cancellation if the service is stopped? Where do I initialize the CancellationTokenSource object and how I cancel it from onStop() method ?
Ashish Singh Feb2022 25-Feb-22 8:00am View    
Thanks. I’ll look into it. It’s getting late out here. Have a nice weekend.
Ashish Singh Feb2022 25-Feb-22 7:44am View    
I understand with the await operator, StateMachine is spun up and this is what gives a sense of multi-threading operation. What I don’t understand is if my calling method (ListenForStatus) will continue to process incoming tcp streams while the ProcessEventsAsync awaits on Task.Delay (which apparently spins up a new thread). I think I’m just cutting some slack asking around instead of testing it myself. I’ll check out the videos you posted, thanks again.