当前位置: 首页>>代码示例>>C#>>正文


C# NSObject.Release方法代码示例

本文整理汇总了C#中NSObject.Release方法的典型用法代码示例。如果您正苦于以下问题:C# NSObject.Release方法的具体用法?C# NSObject.Release怎么用?C# NSObject.Release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NSObject的用法示例。


在下文中一共展示了NSObject.Release方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public static void Run(String arg)
        {
            NSAutoreleasePool pool = new NSAutoreleasePool ();

            NSString CONNECTION_NAME = new NSString ("authentication test");

            if (arg == "server") {
                // Create a generic NSConnection to use to vend an object over DO.
                NSConnection conn = new NSConnection ();

                // Create a generic object to vend over DO; usually this is an object
                // that actually has something interesting to do as a "server".
                NSObject @object = new NSObject ();

                // Create an Authenticator object to authenticate messages that come
                // in to the server.  The client and server need to use the same
                // authentication logic, but would not need to use the same class.
                Authenticator authenticator = new Authenticator ();

                // Configure the connection
                conn.Delegate = authenticator;
                conn.RootObject = @object;

                // Set the name of the root object
                if (!conn.RegisterName (CONNECTION_NAME)) {
                    Console.WriteLine ("OAuthenticator server: could not register server. Is one already running ?");
                    Environment.Exit (1);
                }
                Console.WriteLine ("OAuthenticator server: started");

                // Have the run loop run forever, servicing incoming messages
                NSRunLoop.CurrentRunLoop.Run ();

                // Cleanup objects; not really necessary in this case
                authenticator.Release ();
                @object.Release ();
                conn.Release ();
            } else if (arg == "client") {
                // Create an Authenticator object to authenticate messages going
                // to the server.  The client and server need to use the same
                // authentication logic, but would not need to use the same class.
                Authenticator authenticator = new Authenticator ();
                NSDistantObject proxy;

                // Lookup the server connection
                NSConnection conn = NSConnection.ConnectionWithRegisteredNameHost (CONNECTION_NAME, null);

                if (conn == null) {
                    Console.WriteLine ("OAuthenticator client: could not find server. You need to start one on this machine first.");
                    Environment.Exit (1);
                }

                // Set the authenticator as the NSConnection delegate; all
                // further messages, including the first one to lookup the root
                // proxy, will go through the authenticator.
                conn.Delegate = authenticator;

                proxy = conn.RootProxy;

                if (proxy == null) {
                    Console.WriteLine ("OAuthenticator client: could not get proxy. This should not happen.");
                    Environment.Exit (1);
                }

                // Since this is an example, we don't really care what the "served"
                // object really does, just that we can message it.  Since it is just
                // an NSObject, send it some NSObject messages.  If these aren't
                // authenticated successfully, an NSFailedAuthenticationException
                // exception is raised.
                Console.WriteLine ("description: {0}", proxy.Description);
                Console.WriteLine ("isKindOfClass NSObject ? {0}", proxy.IsKindOfClass (NSObject.NSObjectClass) ? "YES" : "NO");

                Console.WriteLine ("Done. Messages sent successfully.");
            } else {
                Console.WriteLine ("Either server or client must be specified.");
            }

            pool.Release ();
        }
开发者ID:Monobjc,项目名称:monobjc-samples,代码行数:79,代码来源:Program.cs


注:本文中的NSObject.Release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。