Git Product home page Git Product logo

Comments (5)

geoperez avatar geoperez commented on August 17, 2024

Hi,

The anonymous function should not be an issue, my guess is probably the Nuget is not throwing the error visually. If you check the "Output" window in "Debug" option maybe you should see the error too with Nuget.

Related to the issue, are you disposing the webworker when the exception raised?

I'm trying the next code, but I can't get the HttpListenerException.

using System;
using System.ComponentModel;
using Unosquare.Labs.EmbedIO;
using Unosquare.Labs.EmbedIO.Modules;

namespace ConsoleApplication1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var web = new WebWorker((Unosquare.Labs.EmbedIO.WebServer server) =>
            {
                server.Module<Unosquare.Labs.EmbedIO.Modules.WebApiModule>().RegisterController<StorageController>();
                server.Module<Unosquare.Labs.EmbedIO.Modules.WebApiModule>().RegisterController<LogController>();
            });

            web.Start();

            Console.ReadLine();
        }
    }

    internal class StorageController : WebApiController
    {

    }

    internal class LogController : WebApiController
    {

    }

    internal class WebWorker
    {
        private string Url = "http://localhost:9696/";
        private Action<WebServer> doStuff;
        private readonly BackgroundWorker serverWorker;

        public WebWorker(Action<WebServer> doStuff = null)
        {
            this.doStuff = doStuff;
            serverWorker = new BackgroundWorker()
            {
                WorkerReportsProgress = true,
                WorkerSupportsCancellation = true,
            };

            serverWorker.DoWork += DoWorkHandler;
        }

        public void Start()
        {
            serverWorker.RunWorkerAsync(@"C:\unosquare\unosquare.github.io");
        }

        private void DoWorkHandler(object sender, DoWorkEventArgs e)
        {
            using (var server = new WebServer(Url))
            {
                server.RegisterModule(new StaticFilesModule(e.Argument.ToString()));
                server.RegisterModule(new WebApiModule());

                if (doStuff != null)
                {
                    doStuff(server);
                }

                server.RunAsync();

                while (serverWorker.CancellationPending == false)
                {
                    System.Threading.Thread.Sleep(100);
                }
            }
        }
    }
}

from embedio.

srad avatar srad commented on August 17, 2024

I was actually expecting that it was silently happening. And no I'm not explicitly disposing the worker when the exception is raised, if you mean what I think then it's not necessary considering what I read on stackoverflow about this.

from embedio.

geoperez avatar geoperez commented on August 17, 2024

Hey @srad, I'm still trying to reproduce the issue. I added the next code at Webserver.cs line 306

catch (HttpListenerException listenerEx)
{
var errorMessage = listenerEx.ExceptionMessage("Failing HttpListenerException: " + module.Name);
Log.Error(errorMessage, listenerEx);
return;
}

And I created a simple webrequestor to be requesting the index page constantly but the debugger is never hitting the ListenerException.

Can you share me a little bit more your code?

from embedio.

srad avatar srad commented on August 17, 2024

Hi, I hadn't had the time to look thoroughly into this, for now I just ignored the exception.

What I can say is that I served an Html page which contained an <audio> element to a mp3 file, when the exception was raised.

from embedio.

mariodivece avatar mariodivece commented on August 17, 2024

Closing as no further feedback was received and the issue could not be reproduced.

from embedio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.