Files
g.hnyhua.cn/COSXML/Network/TaskManager.cs
2026-02-07 15:48:27 +08:00

59 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Text;
/* ==============================================================================
* Copyright 2016-2019 Tencent Cloud. All Rights Reserved.
* Authbradyxiao
* Date2019/4/4 16:48:10
* ==============================================================================*/
namespace Tencent.QCloud.Cos.Sdk.Network
{
public class TaskManager
{
private Queue<HttpTask> httpTasks;
private static TaskManager instance;
private Object sync;
private TaskManager()
{
httpTasks = new Queue<HttpTask>(30);
sync = new Object();
}
public static TaskManager getInstance()
{
lock (typeof(TaskManager))
{
if (instance == null)
{
instance = new TaskManager();
}
}
return instance;
}
public void Enqueue(HttpTask httpTask)
{
lock (sync)
{
httpTasks.Enqueue(httpTask);
}
}
public HttpTask Dequeue()
{
HttpTask httpTask = null;
lock (sync)
{
if (httpTasks.Count != 0)
{
httpTask = httpTasks.Dequeue();
}
}
return httpTask;
}
}
}