English 中文(简体)
• 如何在新路面建造一个教室?
原标题:How to construct a class in a new thread?

如何在新路面建造一个班子? 我有一个固定类别,称为服务器和一个称为客户Handler的非统计类别。 我愿在一条新路上主持一个新的客户Handler案的施工。 施工人有2个论点。 我尝试了多种办法,但我的工作已看得见,没有增加。 法典如下:

public static class Server
{
    //...

    public static void AcceptConnection(IAsyncResult iar)
    {
        var oldserver = (Socket) iar.AsyncState;
        var client = oldserver.EndAccept(iar);
        Console.WriteLine("Client [{0}] connected from {1}.", CHandlerIndex, client.RemoteEndPoint.ToString());

        new ClientHandler(client, CHandlerIndex); //This has to run in a new thread.

        CHandlerIndex++;
        ServerSocket.BeginAccept(new AsyncCallback(AcceptConnection), ServerSocket);
    }
}

public class ClientHandler
{
    private readonly Socket _client;
    private readonly Parser _pParser;
    public Security S;
    public int ClientIndex;

    //...

    public ClientHandler(Socket cSocket, int cI)
    {
        _client = cSocket;
        InitSecurity();
        _pParser = new Parser(this);
        ClientIndex = cI;
    }

    //...
 }
最佳回答

Async和Threaded不是同义词。 如果你想要新铺面,就能够明确使用一个托马池、一个原始的“新版”(Threadstart...)或研究使用新的任务平行图书馆。

问题回答

而且,班级(目标)没有穿过特定深层。 只有采用的方法。 您的要求是,在另一条路面上管理一名建筑商,这是毫无意义的。 它不会影响其他方法的操作地点。

In the code you have given it looks like the new ClientHandler instance is unrooted, ie it could be Garbage collected.

客户 残疾者是否有其他方法? 他们可能又 on。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签