コード例 #1
0
ファイル: AppHelper.cs プロジェクト: afrog33k/mcocoa
        public static AppHelper Create()
        {
            AppHelper result = new AppHelper(NSObject.AllocAndInitInstance("AppHelper"));

            result.m_thread = new Thread(result.DoThread);
            result.m_thread.Name = "AppHelper";
            result.m_thread.IsBackground = true;
            result.m_thread.Start();

            return result;
        }
コード例 #2
0
ファイル: NSApplication.cs プロジェクト: afrog33k/mcocoa
        /// <summary>Helper used to create an NSApplication subclass.</summary>
        /// <param name = "appClass">The name of the subclass, e.g. "MyApplication".</param>
        /// <param name = "nibName">The name of a nib file, e.g. "MainMenu.nib".</param>
        /// <param name = "extendDebugMenu">Used to add custom items to the debug menu. May be null.</param>
        public static NSApplication Create(string appClass, string nibName, Action<NSMenu> extendDebugMenu)
        {
            NSApplication app = new Class(appClass).Call("sharedApplication").To<NSApplication>();

            ms_mainThread = Thread.CurrentThread;

            // Load our nib. This will instantiate all of the native objects and wire them together.
            // The C# objects will be created the first time a managed method is called.
            NSMutableDictionary dict = NSMutableDictionary.Create();
            bool loaded = NSBundle.mainBundle().loadNibFile_externalNameTable_withZone(
                NSString.Create(nibName), dict, IntPtr.Zero);

            if (!loaded)
                throw new InvalidOperationException("Couldn't load " + nibName + ".");

            // We need an NSAutoreleasePool to do Native.Call, but we don't want to have one
            // hanging around while we're in the main event loop because that may hide bugs.
            // So, we'll instantiate a Native instance here and call Invoke later which can
            // be done without an NSAutoreleasePool.
            ms_run = new Native(app, new Selector("run"));

            ms_helper = AppHelper.Create();
            #if DEBUG
            app.BeginInvoke(() => DoInitDebugMenu(extendDebugMenu));
            #endif

            ms_startupPool.release();
            ms_startupPool = null;

            return app;
        }