Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About _Server.Stop() #204

Open
FreeVB opened this issue Nov 18, 2023 · 5 comments
Open

About _Server.Stop() #204

FreeVB opened this issue Nov 18, 2023 · 5 comments

Comments

@FreeVB
Copy link

FreeVB commented Nov 18, 2023

Hello, why did I put _Server.Logger=PrintServeLog; Then call _Server.Stop(); Here's the code for the PrintServeLog, which outputs connection information to a ListBox.

private void PrintServeLog(string msg)
{
    try
    {
        if (uiListBoxServe.Items.Count > 1000) uiListBoxServe.Items.Clear();
        if (uiListBoxServe.InvokeRequired) // 检查我们是否与控件的线程不同
        {
            uiListBoxServe.Invoke(new Action(() => uiListBoxServe.Items.Insert(0, msg)));
        }
        else
        {
            uiListBoxServe.Items.Insert(0, msg);
        }
    }
    catch (Exception ex)
    {
        if (uiListBoxServe.InvokeRequired) // 检查我们是否与控件的线程不同
        {
            uiListBoxServe.Invoke(new Action(() => uiListBoxServe.Items.Insert(0, "错误:" + ex.Message)));
        }
        else
        {
            uiListBoxServe.Items.Insert(0, "错误:" + ex.Message);
        }
    }
}
@FreeVB
Copy link
Author

FreeVB commented Nov 18, 2023

private void PrintServeLog(string msg)
{
    try
    {
        if (uiListBoxServe.Items.Count > 1000)
        {
            if (uiListBoxServe.InvokeRequired)
            {
                uiListBoxServe.BeginInvoke(new Action(() => uiListBoxServe.Items.Clear()));
            }
            else
            {
                uiListBoxServe.Items.Clear();
            }
        }

        if (uiListBoxServe.InvokeRequired)
        {
            uiListBoxServe.BeginInvoke(new Action(() => uiListBoxServe.Items.Insert(0, msg)));
        }
        else
        {
            uiListBoxServe.Items.Insert(0, msg);
        }
    }
    catch (Exception ex)
    {
        if (uiListBoxServe.InvokeRequired)
        {
            uiListBoxServe.BeginInvoke(new Action(() => uiListBoxServe.Items.Insert(0, "错误:" + ex.Message)));
        }
        else
        {
            uiListBoxServe.Items.Insert(0, "错误:" + ex.Message);
        }
    }
}

I tried using this method so that the UI doesn't respond to the problem solving, but _Server doesn't stop, but instead returns an error like this: System Net Sockets SocketException (995): I/O operation aborted due to thread exit or application request.

@FreeVB
Copy link
Author

FreeVB commented Nov 18, 2023

Unless I add to Task AcceptConnections(). ||ex is SocketException no longer gives the error message, but I'm not sure if that's right.

@jchristn
Copy link
Owner

Hi @FreeVB thanks for your note. I'm sorry but I'm not fully understanding what the issue is that you are encountering. Could you try to describe it again?

@FreeVB
Copy link
Author

FreeVB commented Nov 19, 2023

Set PrintServeLog to _Server.Logger=PrintServeLog; , the service cannot be stopped. Or an error message appears.

@jchristn
Copy link
Owner

@FreeVB Hi, this seems like an issue caused by the implementation using forms. Were you able to resolve it? Can you identify where it hangs, or, supply the error message that appears?

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

No branches or pull requests

2 participants