当前位置: 首页>>代码示例>>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;未经允许,请勿转载。