コード例 #1
0
        public async Task <QueueObject <T> > Pop(TimeSpan?invisibleTimeSpan = null, Action <QueueObject <T> > action = null)
        {
            CloudQueue queue = await GetQueueAsync();

            CloudQueueMessage peekedMessage = await queue.GetMessageAsync(invisibleTimeSpan ?? TimeSpan.FromSeconds(3), new QueueRequestOptions(), new OperationContext());

            if (peekedMessage != null)
            {
                QueueObject <T> queueObject = JsonConvert.DeserializeObject <QueueObject <T> >(peekedMessage.AsString);
                if (action != null)
                {
                    try
                    {
                        action(queueObject);
                        await queue.DeleteMessageAsync(peekedMessage);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }

                return(queueObject);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public async Task Push(QueueObject <T> queueObject)
        {
            CloudQueue queue = await GetQueueAsync();

            var text = JsonConvert.SerializeObject(queueObject);
            CloudQueueMessage message = new CloudQueueMessage(text);
            await queue.AddMessageAsync(message);
        }