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


C# TaskCompletionSource.SafeSetException方法代码示例

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


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

示例1: ExecMultiAddRemove

        private Task<long> ExecMultiAddRemove(int db, RedisLiteral command, string key, byte[][] values, bool queueJump)
        {
            RedisFeatures features;
            if (values.Length > 1 && ((features = Features) == null || !features.SetVaradicAddRemove))
            {
                RedisTransaction tran = this as RedisTransaction;
                bool execute = false;
                if (tran == null)
                {
                    tran = CreateTransaction();
                    execute = true;
                }
                Task<bool>[] tasks = new Task<bool>[values.Length];

                for (int i = 0; i < values.Length; i++)
                {
                    tasks[i] = ExecuteBoolean(RedisMessage.Create(db, command, key, values[i]), queueJump);
                }
                TaskCompletionSource<long> final = new TaskCompletionSource<long>();
                tasks[values.Length - 1].ContinueWith(t =>
                {
                    try
                    {
                        if (t.ShouldSetResult(final))
                        {
                            long count = 0;
                            for (int i = 0; i < tasks.Length; i++)
                            {
                                if (tran.Wait(tasks[i]))
                                {
                                    count++;
                                }
                            }
                            final.TrySetResult(count);
                        }
                    }
                    catch (Exception ex)
                    {
                        final.SafeSetException(ex);
                    }
                });
                if (execute) tran.Execute(queueJump);
                return final.Task;
            }
            else
            {
                var args = new RedisMessage.RedisParameter[values.Length + 1];
                args[0] = key;
                for (int i = 0; i < values.Length; i++)
                {
                    args[i + 1] = values[i];
                }
                return ExecuteInt64(RedisMessage.Create(db, command, args), queueJump);
            }
        }
开发者ID:raycode,项目名称:booksleeve,代码行数:55,代码来源:ISetCommands.cs

示例2: CreateTransaction

        Task<long> IHashCommands.Remove(int db, string key, string[] fields, bool queueJump)
        {
            RedisFeatures features;
            if (fields.Length > 1 && ((features = Features) == null || !features.HashVaradicDelete))
            {
                RedisTransaction tran = this as RedisTransaction;
                bool execute = false;
                if (tran == null)
                {
                    tran = CreateTransaction();
                    execute = true;
                }
                Task<bool>[] tasks = new Task<bool>[fields.Length];

                var hashes = tran.Hashes;
                for (int i = 0; i < fields.Length; i++)
                {
                    tasks[i] = hashes.Remove(db, key, fields[i], queueJump);
                }
                TaskCompletionSource<long> final = new TaskCompletionSource<long>();
                tasks[fields.Length - 1].ContinueWith(t =>
                {

                    try
                    {
                        if (t.ShouldSetResult(final))
                        {
                            long count = 0;
                            for (int i = 0; i < tasks.Length; i++)
                            {
                                if (tran.Wait(tasks[i]))
                                {
                                    count++;
                                }
                            }
                            final.TrySetResult(count);
                        }
                    }
                    catch (Exception ex)
                    {
                        final.SafeSetException(ex);
                    }
                });
                if (execute) tran.Execute(queueJump);
                return final.Task;
            }
            else
            {
                return ExecuteInt64(RedisMessage.Create(db, RedisLiteral.HDEL, key, fields), queueJump);
            }
        }
开发者ID:raycode,项目名称:booksleeve,代码行数:51,代码来源:IHashCommands.cs


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