SuperSimpleTcp icon indicating copy to clipboard operation
SuperSimpleTcp copied to clipboard

About _Server.Stop()

Open FreeVB opened this issue 2 years ago • 5 comments

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 avatar Nov 18 '23 00:11 FreeVB

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 avatar Nov 18 '23 00:11 FreeVB

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

FreeVB avatar Nov 18 '23 01:11 FreeVB

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?

jchristn avatar Nov 18 '23 05:11 jchristn

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

FreeVB avatar Nov 19 '23 00:11 FreeVB

@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?

jchristn avatar Jan 16 '24 16:01 jchristn