當前位置: 首頁>>代碼示例>>C#>>正文


C# Promise.TrySetCompleted方法代碼示例

本文整理匯總了C#中Promise.TrySetCompleted方法的典型用法代碼示例。如果您正苦於以下問題:C# Promise.TrySetCompleted方法的具體用法?C# Promise.TrySetCompleted怎麽用?C# Promise.TrySetCompleted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Promise的用法示例。


在下文中一共展示了Promise.TrySetCompleted方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: LoadEditor


//.........這裏部分代碼省略.........
                {
                    RequireDotNetRuntime = true,
                    CaptureStandartError = false,
                    CaptureStandartOutput = false,
                    ExecutionTimeout = TimeSpan.Zero,
                    WaitForExit = false,
                    StartInfo =
                    {
                        EnvironmentVariables =
                        {
                            { "CHARON_APP_DATA", Settings.GetAppDataPath() },
                            { "CHARON_LICENSE_SERVER", Settings.Current.LicenseServerAddress },
                            { "CHARON_SELECTED_LICENSE", Settings.Current.SelectedLicense },
                        }
                    }
                }
            );

            toolsProcessTask.ContinueWith(t =>
            {
                if (t.HasErrors) return;
                using (var result = toolsProcessTask.GetResult())
                    GameDataEditorProcess.Watch(result.Process.Id, result.Process.ProcessName);
            });

            if (Settings.Current.Verbose)
                Debug.Log("Launching gamedata editor process.");

            // wait untill server process start
            var timeoutPromise = Promise.Delayed(TimeSpan.FromSeconds(10));
            var startPromise = toolsProcessTask.IgnoreFault();
            var startCompletePromise = Promise.WhenAny(timeoutPromise, startPromise);
            var cancelPromise = new Coroutine<bool>(RunCancellableProgress(title, Resources.UI_UNITYPLUGIN_WINDOWEDITORLAUNCHINGEXECUTABLE, 0.65f, 0.80f, TimeSpan.FromSeconds(5), startCompletePromise));

            yield return Promise.WhenAny(timeoutPromise, startPromise, cancelPromise);
            if (timeoutPromise.IsCompleted)
            {
                Debug.LogWarning(Resources.UI_UNITYPLUGIN_WINDOWFAILEDTOSTARTEDITORTIMEOUT);
                yield break;
            }
            else if (cancelPromise.IsCompleted)
            {
                if (EditorApplication.isCompiling)
                    throw new InvalidOperationException("Interrupted by script compiler.");
                else
                    throw new InvalidOperationException("Interrupted by user.");
            }

            if (EditorUtility.DisplayCancelableProgressBar(title, Resources.UI_UNITYPLUGIN_WINDOWEDITORLAUNCHINGEXECUTABLE, 0.80f))
                throw new InvalidOperationException("Interrupted by user.");
            if (EditorApplication.isCompiling)
                throw new InvalidOperationException("Interrupted by script compiler.");

            // wait untill server start to respond
            timeoutPromise = Promise.Delayed(TimeSpan.FromSeconds(10));
            startPromise = HttpUtils.Download(new Uri(gameDataEditorUrl), timeout: TimeSpan.FromSeconds(1));
            startCompletePromise = new Promise();
            cancelPromise = new Coroutine<bool>(RunCancellableProgress(title, Resources.UI_UNITYPLUGIN_WINDOWEDITORLAUNCHINGEXECUTABLE, 0.80f, 0.90f, TimeSpan.FromSeconds(5), startCompletePromise));
            while (!timeoutPromise.IsCompleted)
            {
                yield return startPromise.IgnoreFault();
                if (startPromise.HasErrors == false)
                    break;
                else
                    startPromise = HttpUtils.Download(new Uri(gameDataEditorUrl), timeout: TimeSpan.FromSeconds(1));
            }
            if (timeoutPromise.IsCompleted && (!startPromise.IsCompleted || startPromise.HasErrors))
            {
                startCompletePromise.TrySetCompleted();
                Debug.LogWarning(Resources.UI_UNITYPLUGIN_WINDOWFAILEDTOSTARTEDITORTIMEOUT);
                yield break;
            }
            startCompletePromise.TrySetCompleted();

            if (EditorUtility.DisplayCancelableProgressBar(title, Resources.UI_UNITYPLUGIN_WINDOWEDITOROPENINGBROWSER, 0.95f))
                throw new InvalidOperationException("Interrupted by user.");
            if (EditorApplication.isCompiling)
                throw new InvalidOperationException("Interrupted by script compiler.");

            switch ((Browser)Settings.Current.Browser)
            {
                case Browser.UnityEmbedded:
                    var nearPanels = typeof(SceneView);
                    var editorWindow = GetWindow<GameDataEditorWindow>(nearPanels);
                    editorWindow.titleContent = new GUIContent(title);
                    editorWindow.LoadUrl(gameDataEditorUrl + reference);
                    editorWindow.SetWebViewVisibility(true);
                    editorWindow.Repaint();
                    editorWindow.Focus();
                    break;
                case Browser.Custom:
                    if (string.IsNullOrEmpty(Settings.Current.BrowserPath))
                        goto case Browser.SystemDefault;
                    Process.Start(Settings.Current.BrowserPath, gameDataEditorUrl + reference);
                    break;
                case Browser.SystemDefault:
                    EditorUtility.OpenWithDefaultApp(gameDataEditorUrl + reference);
                    break;
            }
        }
開發者ID:deniszykov,項目名稱:charon-unity3d,代碼行數:101,代碼來源:GameDataEditorWindow.cs

示例2: ShowAsync

        public static Promise ShowAsync(bool autoClose = true)
        {
            var promise = new Promise();
            var window = GetWindow<LicenseActivationWindow>(utility: true);

            window.Done += (sender, args) => promise.TrySetCompleted();
            window.Cancel += (sender, args) => promise.TrySetFailed(args.GetException());

            window.Focus();

            return promise;
        }
開發者ID:deniszykov,項目名稱:charon-unity3d,代碼行數:12,代碼來源:LicenseActivationWindow.cs

示例3: ShowAsync

        public static Promise ShowAsync(bool autoClose = true)
        {
            var promise = new Promise();
            var window = GetWindow<UpdateRuntimeWindow>(utility: true);

            window.Done += (sender, args) => promise.TrySetCompleted();
            window.Cancel += (sender, args) => promise.TrySetFailed(args.GetException());

            window.monoPath = string.IsNullOrEmpty(ToolsRunner.MonoPath) ? MonoDefaultLocation : ToolsRunner.MonoPath;
            window.autoClose = autoClose;
            if (ToolsRunner.IsWindows)
                window.runtimeVersion = ToolsRunner.Get45or451FromRegistry();

            window.RunCheck();
            window.Focus();

            if (Settings.Current.Verbose)
                Debug.Log(string.Format("Showing '{0}' window. Where current mono location: '{1}'.", window.titleContent.text, window.monoPath));

            return promise;
        }
開發者ID:deniszykov,項目名稱:charon-unity3d,代碼行數:21,代碼來源:UpdateRuntimeWindow.cs


注:本文中的Promise.TrySetCompleted方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。