Limit the number of loops waiting for events, on HndCardBoard and HndChat.
This commit is contained in:
@@ -13,6 +13,8 @@ namespace VAR.Focus.Web.Controls
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
|
private const int MaxWaitLoops = 5;
|
||||||
|
|
||||||
private static object _monitor = new object();
|
private static object _monitor = new object();
|
||||||
private static Dictionary<int, CardBoard> _cardBoards = new Dictionary<int, CardBoard>();
|
private static Dictionary<int, CardBoard> _cardBoards = new Dictionary<int, CardBoard>();
|
||||||
|
|
||||||
@@ -116,22 +118,23 @@ namespace VAR.Focus.Web.Controls
|
|||||||
int timePoolData = Convert.ToInt32(string.IsNullOrEmpty(strTimePoolData) ? "0" : strTimePoolData);
|
int timePoolData = Convert.ToInt32(string.IsNullOrEmpty(strTimePoolData) ? "0" : strTimePoolData);
|
||||||
|
|
||||||
CardBoard cardBoard = GetCardBoard(idBoard);
|
CardBoard cardBoard = GetCardBoard(idBoard);
|
||||||
bool mustWait = (timePoolData > 0);
|
int waitCount = (timePoolData > 0) ? MaxWaitLoops : 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
List<ICardEvent> listMessages = cardBoard.Cards_GetEventList(idCardEvent);
|
List<ICardEvent> listMessages = cardBoard.Cards_GetEventList(idCardEvent);
|
||||||
if (listMessages.Count > 0)
|
if (listMessages.Count > 0)
|
||||||
{
|
{
|
||||||
mustWait = false;
|
waitCount = 0;
|
||||||
context.ResponseObject(listMessages);
|
context.ResponseObject(listMessages);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mustWait)
|
if (waitCount > 0)
|
||||||
{
|
{
|
||||||
lock (_monitor) { Monitor.Wait(_monitor, timePoolData); }
|
lock (_monitor) { Monitor.Wait(_monitor, timePoolData); }
|
||||||
|
waitCount--;
|
||||||
}
|
}
|
||||||
} while (mustWait);
|
} while (waitCount > 0);
|
||||||
context.ResponseObject(new List<Message>());
|
context.ResponseObject(new List<Message>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace VAR.Focus.Web.Controls
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
|
private const int MaxWaitLoops = 5;
|
||||||
|
|
||||||
private static object _monitor = new object();
|
private static object _monitor = new object();
|
||||||
private static Dictionary<string, MessageBoard> _chatBoards = new Dictionary<string, MessageBoard>();
|
private static Dictionary<string, MessageBoard> _chatBoards = new Dictionary<string, MessageBoard>();
|
||||||
|
|
||||||
@@ -56,7 +58,7 @@ namespace VAR.Focus.Web.Controls
|
|||||||
int timePoolData = Convert.ToInt32(string.IsNullOrEmpty(strTimePoolData) ? "0" : strTimePoolData);
|
int timePoolData = Convert.ToInt32(string.IsNullOrEmpty(strTimePoolData) ? "0" : strTimePoolData);
|
||||||
|
|
||||||
MessageBoard messageBoard;
|
MessageBoard messageBoard;
|
||||||
bool mustWait = (timePoolData > 0);
|
int waitCount = (timePoolData > 0) ? MaxWaitLoops : 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (_chatBoards.ContainsKey(idMessageBoard) == false)
|
if (_chatBoards.ContainsKey(idMessageBoard) == false)
|
||||||
@@ -77,16 +79,17 @@ namespace VAR.Focus.Web.Controls
|
|||||||
List<Message> listMessages = messageBoard.Messages_GetList(idMessage);
|
List<Message> listMessages = messageBoard.Messages_GetList(idMessage);
|
||||||
if (listMessages.Count > 0)
|
if (listMessages.Count > 0)
|
||||||
{
|
{
|
||||||
mustWait = false;
|
waitCount = 0;
|
||||||
context.ResponseObject(listMessages);
|
context.ResponseObject(listMessages);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mustWait)
|
if (waitCount > 0)
|
||||||
{
|
{
|
||||||
lock (_monitor) { Monitor.Wait(_monitor, timePoolData); }
|
lock (_monitor) { Monitor.Wait(_monitor, timePoolData); }
|
||||||
|
waitCount--;
|
||||||
}
|
}
|
||||||
} while (mustWait);
|
} while (waitCount > 0);
|
||||||
context.ResponseObject(new List<Message>());
|
context.ResponseObject(new List<Message>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user