Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

IHostedService Stop without any reason #1332

Closed
btbensoft opened this issue Feb 17, 2018 · 3 comments
Closed

IHostedService Stop without any reason #1332

btbensoft opened this issue Feb 17, 2018 · 3 comments

Comments

@btbensoft
Copy link

Hello,

Could anyone explain to me why my server stopped for no reason?
below my IHostedService implementation:

public class HostServiceBox : IHostedService
    {
        public Task StartAsync(CancellationToken cancellationToken)
        {
            return Task.Run(() =>
            {
                DomonutyBoxBusiness.StartBoxListening(); //STARTUP Box listening

                while (true)
                {
                    Logging.Info(DateTime.Now + " HostServiceBox Running");
                    Thread.Sleep(10000);
                }
            }, cancellationToken);
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            Logging.Info(DateTime.Now + " StopAsync");

            //TODO impplement a Stop litening all boxes
            throw new NotImplementedException();
        }
    }

Here is my log?

......
2/17/2018 3:02:47 PM HostServiceBox Running
2/17/2018 3:02:57 PM HostServiceBox Running
2/17/2018 3:03:07 PM HostServiceBox Running
2/17/2018 3:03:17 PM HostServiceBox Running
2/17/2018 3:03:27 PM HostServiceBox Running
2/17/2018 3:03:37 PM HostServiceBox Running
2/17/2018 3:03:47 PM HostServiceBox Running
2/17/2018 4:22:04 PM StopAsync
2/17/2018 5:18:37 PM HostServiceBox Running
2/17/2018 5:18:47 PM HostServiceBox Running
2/17/2018 5:18:57 PM HostServiceBox Running
2/17/2018 5:19:07 PM HostServiceBox Running
2/17/2018 5:19:17 PM HostServiceBox Running
2/17/2018 5:19:27 PM HostServiceBox Running
2/17/2018 5:19:37 PM HostServiceBox Running
2/17/2018 5:19:47 PM HostServiceBox Running
2/17/2018 5:19:57 PM HostServiceBox Running
2/17/2018 5:20:07 PM HostServiceBox Running
......

I host this project on IIS with kestrel (.Net Core).

The problem is that I have a socket that listens in this line:

DomonutyBoxBusiness.StartBoxListening(); //STARTUP Box listening

And when we look at my log my socket does not listen to 3:03:47 PM at 5:18:37 PM

Anyone can help me?

@davidfowl
Copy link
Member

Well it's always stopped for a reason, perhaps an application pool recycle caused the issue.

@btbensoft
Copy link
Author

I unterstand but i got nothing error in my log.

Even today my background task stoped! without call StopAsync :S.

.....
2/24/2018 8:31:27 PM HostServiceBox Running
2/24/2018 8:32:27 PM HostServiceBox Running
2/24/2018 8:33:27 PM HostServiceBox Running
2/24/2018 8:34:27 PM HostServiceBox Running  <------
2/25/2018 11:22:07 AM HostServiceBox Running <-----
2/25/2018 11:23:07 AM HostServiceBox Running
2/25/2018 11:24:07 AM HostServiceBox Running
2/25/2018 11:25:07 AM HostServiceBox Running
2/25/2018 11:26:07 AM HostServiceBox Running
2/25/2018 11:27:07 AM HostServiceBox Running
2/25/2018 11:28:07 AM HostServiceBox Running
2/25/2018 11:29:07 AM HostServiceBox Running
2/25/2018 11:30:07 AM HostServiceBox Running
.....

is look like on IIS with kestrel (.Net Core) my method slept ? Why?

@btbensoft
Copy link
Author

I got an answer on Stack Overflow

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants