0

だから、私はTcpChannelsを使用してさまざまなクライアントとサーバーを巻き込むプロジェクトを開発しています

また、サーバーをフリーズする特定の操作が 1 つあります。サーバーが遅く見えるようにします。フリーズが解除されるまで、サーバーはリモート呼び出しに応答しません。私はこれをロック、monitor.wait、およびmonitor.pulseで行います

問題は、チャネルの「タイムアウト」プロパティを明示的に定義したにもかかわらず、フリーズしたサーバーではいずれにしても有効期限が切れないことです。

簡単な例を次に示します。

サーバー :

    public class Server
    static void Main(string[] args) {
        HelloService myRem = null;

        TcpChannel channel = new TcpChannel(8086);
        ChannelServices.RegisterChannel(channel, true);

        myRem = new HelloService();
        RemotingServices.Marshal(myRem, "HelloService");

        System.Console.WriteLine("<enter> to exit...");
        System.Console.ReadLine();
    }

    public class HelloServer : MarshalByRef {

        private bool freezed = true;

        public string Hello() {
            while (freezed)
                lock (this)
                    Monitor.Wait(this);

            return "Hello World!";
        }
    }

クライアント:

public class Client
{
    static void Main()
    {
        IDictionary propBag = new Hashtable();
        propBag["name"] = "tpc";
        propBag["timeout"] = 3000;
        TcpChannel channel = new TcpChannel(propBag, null, null);
        ChannelServices.RegisterChannel(channel, false);
        HelloService obj = (HelloService)Activator.GetObject(typeof(HelloService), "tcp://localhost:8086/HelloService");

        while (true)
        {
            try
            {
                Console.WriteLine(obj.Hello());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetType());
                Console.WriteLine("TIMEOUT");
            }
        }
    }
}

私のコンピューターでは、クライアント側の呼び出しは期限切れになりません

私が絶望的な暫定的なlock (this)声明を削除するまで

そして、それは働き始めました!SocketException しかし今、私は理由を理解することがMonitor.waitできます

これが私のコンピューターで機能するのはなぜですか? 私は他の人で試しましたが、私はこの問題を抱えていませんでした

編集

実際、他のコンピューターではタイムアウト例外を取得できませんが、ロック外でモニターを呼び出すと同期例外が発生します

4

0 に答える 0