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


C# System.Threading.Tasks.TaskCompletionSource.SetResult方法代码示例

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


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

示例1: LoginAsync

    public static System.Threading.Tasks.Task LoginAsync(string username, string password)
    {
        var tcs = new System.Threading.Tasks.TaskCompletionSource<PTPrincipal>();

        PTIdentity.GetPTIdentity(username, password, (o, e) =>
        {
            if (e.Error == null && e.Object != null)
            {
                SetPrincipal(e.Object);
                tcs.SetResult(null);
            }
            else
            {
                Logout();
                if (e.Error != null) 
                    tcs.SetException(e.Error.InnerException);
                else
                    tcs.SetCanceled();
            }
        });
        return tcs.Task;
    }
开发者ID:ChrisWay,项目名称:csla,代码行数:22,代码来源:PTPrincipal.cs

示例2: Delay

 /// <summary>
 /// Task.Delayが.NET 4だと搭載されていないので擬似関数作成
 /// </summary>
 /// <param name="milliseconds"></param>
 private void Delay(int milliseconds)
 {
     var tcs = new System.Threading.Tasks.TaskCompletionSource<object>();
     new System.Threading.Timer(_ => tcs.SetResult(null)).Change(milliseconds, -1);
     tcs.Task.Wait();
 }
开发者ID:BuminMacintosh,项目名称:FFXIV_Tools_WPF,代码行数:10,代码来源:TextTalker.cs

示例3: FadeToBlackAsync

 private System.Threading.Tasks.Task FadeToBlackAsync()
 {
     CallFadeOut.Visibility = Visibility.Visible;
     var tcs = new System.Threading.Tasks.TaskCompletionSource<object>();
     EventHandler<object> completed = null;
     completed = (o, e) =>
     {
         FadeToBlack.Completed -= completed;
         tcs.SetResult(null);
     };
     FadeToBlack.Completed += completed;
     FadeToBlack.Begin();
     return tcs.Task;
 }
开发者ID:mbin,项目名称:Win81App,代码行数:14,代码来源:Call.xaml.cs

示例4: GetInitialUrlAsync

        public async override System.Threading.Tasks.Task<Uri> GetInitialUrlAsync()
        {
            // just return if no replacement requested
            if (string.IsNullOrEmpty(replacementUrlFormat))
                return await base.GetInitialUrlAsync();

            // get base class Uri
            System.Diagnostics.Debug.WriteLine("GetUriFromTaskUri: replacementUrlFormat:" + replacementUrlFormat);
            Uri uri = await base.GetInitialUrlAsync();
            System.Diagnostics.Debug.WriteLine("GetUriFromTaskUri: base.uri:" + uri);

            // need to extract state query string from base Uri because its scope isn't public.
            string baseUrl = uri.OriginalString;
            int stateIndex = baseUrl.LastIndexOf("&state=");
            string requestState = baseUrl.Substring(stateIndex + "&state=".Length);

            // verify that the base Url is same as our supposedly identical procedure. If not, there must be a code change in a new version of base class.
            string redoUrl = string.Format(
                             "{0}?client_id={1}&redirect_uri={2}&response_type={3}&scope={4}&state={5}",
                            AuthorizeUrl.AbsoluteUri,
                            Uri.EscapeDataString(ClientId),
                            Uri.EscapeDataString(RedirectUrl.AbsoluteUri),
                            AccessTokenUrl == null ? "token" : "code",
                            Uri.EscapeDataString(Scope),
                            Uri.EscapeDataString(requestState));
            if (baseUrl != redoUrl)
                throw new ArgumentException("GetInitialUrlAsync: Url comparison failure: base: " + baseUrl + " redo:" + redoUrl);

            // format replacement Uri
            uri = new Uri(string.Format(
                            replacementUrlFormat,
                            AuthorizeUrl.AbsoluteUri,
                            Uri.EscapeDataString(ClientId),
                            Uri.EscapeDataString(RedirectUrl.AbsoluteUri),
                            AccessTokenUrl == null ? "token" : "code",
                            Uri.EscapeDataString(Scope),
                            Uri.EscapeDataString(requestState)));
            System.Diagnostics.Debug.WriteLine("GetUriFromTaskUri: replacement uri:" + uri);

            System.Threading.Tasks.TaskCompletionSource<Uri> tcs = new System.Threading.Tasks.TaskCompletionSource<Uri>();
            tcs.SetResult(uri);
            return uri;
        }
开发者ID:patsy02,项目名称:KompetansetorgetXamarin,代码行数:43,代码来源:uauthimpl.cs

示例5: GetResponseAsync

 public System.Threading.Tasks.Task<IResponse> GetResponseAsync(System.Threading.CancellationToken cancellationToken)
 {
     System.Threading.Tasks.TaskCompletionSource<IResponse> tcs = new System.Threading.Tasks.TaskCompletionSource<IResponse>();
     tcs.SetResult(new ResponseImpl(xrequest.GetResponseAsync(cancellationToken)));
     return tcs.Task;
 }
开发者ID:patsy02,项目名称:KompetansetorgetXamarin,代码行数:6,代码来源:uauthimpl.cs

示例6: RequestTimeAsync

		/// <summary>
		/// Returns an awaitable task whose result is the current time from the NTP server specified in the constructor.
		/// </summary>
		/// <remarks>
		/// <para>This method may throw exceptions (most likely a <seealso cref="NtpNetworkException"/> if an error occurs trying to connect/bind to the network endpoint. Exception handling in client code is recommended.</para>
		/// </remarks>
		/// <seealso cref="NtpNetworkException"/>
		public System.Threading.Tasks.Task<DateTime> RequestTimeAsync()
		{
			var tcs = new System.Threading.Tasks.TaskCompletionSource<DateTime>();
			var client = new NtpClient(_ServerAddress);

			var timeReceivedHandler = new EventHandler<NtpTimeReceivedEventArgs>(
				(sender, args) => 
				{
					tcs.SetResult(args.CurrentTime);
				}
			);
			var errorOccurredHandler = new EventHandler<NtpNetworkErrorEventArgs>(
				(sender, args) => 
				{
					if (!tcs.Task.IsCanceled && !tcs.Task.IsCompleted)
						tcs.SetException(args.Exception);
				}
			);

			client.TimeReceived += timeReceivedHandler;
			client.ErrorOccurred += errorOccurredHandler;

			var retVal = tcs.Task;
			tcs.Task.ContinueWith(
				(pt) =>
				{
					client.TimeReceived -= timeReceivedHandler;
					client.ErrorOccurred -= errorOccurredHandler;
				}
			);

			client.BeginRequestTime();

			return retVal;
		}
开发者ID:Yortw,项目名称:Yort.Ntp,代码行数:42,代码来源:NtpClient.cs

示例7: GetAccessTokenAsync

		public virtual System.Threading.Tasks.Task<TwitterAsyncResult<OAuthAccessToken>> GetAccessTokenAsync(OAuthRequestToken requestToken, string verifier)
		{
			var tcs = new System.Threading.Tasks.TaskCompletionSource<TwitterAsyncResult<OAuthAccessToken>>();

			GetAccessToken(requestToken, verifier,
				(token, response) =>
				{
					tcs.SetResult(new TwitterAsyncResult<OAuthAccessToken>(token, response));
				}
			);

			return tcs.Task;
		}
开发者ID:FrenchW,项目名称:tweetmoasharp,代码行数:13,代码来源:TwitterService.OAuth.cs

示例8: GetAccessTokenWithXAuthAsync

		public virtual System.Threading.Tasks.Task<TwitterAsyncResult<OAuthAccessToken>> GetAccessTokenWithXAuthAsync(string username, string password)
		{
			var tcs = new System.Threading.Tasks.TaskCompletionSource<TwitterAsyncResult<OAuthAccessToken>>();

			GetAccessTokenWithXAuth(username, password, (token, response) =>
			{
				tcs.SetResult(new TwitterAsyncResult<OAuthAccessToken>(token, response));
			});

			return tcs.Task;
		}
开发者ID:FrenchW,项目名称:tweetmoasharp,代码行数:11,代码来源:TwitterService.OAuth.cs

示例9: GetRequestTokenAsync

		public virtual System.Threading.Tasks.Task<TwitterAsyncResult<OAuthRequestToken>> GetRequestTokenAsync()
		{
			var tcs = new System.Threading.Tasks.TaskCompletionSource<TwitterAsyncResult<OAuthRequestToken>>();

			GetRequestToken((token, response) =>
			{
				tcs.SetResult(new TwitterAsyncResult<OAuthRequestToken>(token, response));
			});

			return tcs.Task;
		}
开发者ID:FrenchW,项目名称:tweetmoasharp,代码行数:11,代码来源:TwitterService.OAuth.cs

示例10: Main

        /// <summary>
        /// Service main entry point
        /// </summary>
        /// <param name="args">
        /// Startup parameters
        /// </param>
        public static void Main(string[] args)
        {
            // preset logger
            var loggerConfig = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.ColoredConsole();
            var logger = loggerConfig.CreateLogger();
            Log.Logger = logger;

            var arguments = new Docopt().Apply(CommandUsage, args, exit: true);
            var configurations = new List<string>();

            ValueObject config;
            if (arguments.TryGetValue("--config", out config) && config != null)
            {
                configurations.Add(config.ToString());
            }

            Container = new WindsorContainer();

            AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
                {
                    Log.Logger.Error(
                        eventArgs.ExceptionObject as Exception,
                        "{Type}: Unhandled domain exception from {SenderType}, terminating: {IsTerminating}\n{StackTrace}", 
                        "System",
                        sender?.GetType().Name ?? "unknown",
                        eventArgs.IsTerminating,
                        (eventArgs.ExceptionObject as Exception)?.StackTrace);
                };

            var system = Bootstrapper.ConfigureAndStart(Container, configurations.ToArray());
            Log.Logger.Warning("{Type}: Started", "System");
            Console.CancelKeyPress += (sender, eventArgs) =>
                {
                    Log.Logger.Warning("{Type}: Shutdown sequence initiated", "System");
                    var cluster = Akka.Cluster.Cluster.Get(system);

                    var timeout = TimeSpan.FromSeconds(10);
                    if (cluster.IsTerminated || cluster.State.Members.Count == 0)
                    {
                        system.Terminate().Wait(timeout);
                    }
                    else
                    {
                        cluster.LeaveAsync().Wait(timeout);
                        system.Terminate().Wait(timeout);
                    }

                    Log.Logger.Warning("{Type}: Hard stopped", "System");
                    eventArgs.Cancel = true;
                };

            system.StartNameSpaceActorsFromConfiguration();
            BaseInstaller.RunPostStart(Container);

            var waitedTask = new System.Threading.Tasks.TaskCompletionSource<bool>();
            system.WhenTerminated.ContinueWith(task => waitedTask.SetResult(true));
            waitedTask.Task.Wait();
            Log.Logger.Warning("{Type}: Stopped", "System");
        }
开发者ID:kantora,项目名称:ClusterKit,代码行数:65,代码来源:Program.cs


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