C
Curious
I have following code:
void DownloadLists ()
{
if (!mIsListsDownloaded)
{
// Loop -- Downloading entries for each list
foreach (ITritonList list in
TritonListManager.GetLists(true))
{
list.OpenEntries(new
ListDataReadyDelegate(OnEntriesDownloaded));
}
// Wrong in here, because the entries are not
downloaded at this time!!!
mIsListsDownloaded = true;
}
}
void OnEntriesDownloaded(IGridList list)
{
foreach (IGridEntry entry in list.Entries)
{
mEntries.Add(entry);
}
loggerCash.LogMessageBarMessage(ESeverity.Detail,
"Finished downloading entries on list " + list.Name.ToString());
}
The task is to download entries on each list for multiple lists and
then set "mIsListsDownloaded" to true. It's important that the action
"OnEntriesDownloaded" be completed for all of the lists before
"mIsListsDownloaded" is set to true.
I've found this a technical challenge -
The delegate method "OnEntriesDownloaded" takes time to complete.
Also, since "OnEntriesDownloaded" is called for each list and there
are multiple lists, it is called multiple times and it takes
significant amount of time (about 6 seconds, could take even longer
depending on how busy the system is) to complete.
Now the question is that when shall I set "mIsEntriesDownloaded" to
true? I want to wait for 8 seconds because by that time, all of the
entries should have been downloaded. However, there is no guarantee
because sometimes the system takes much longer.
I also don't know the C# syntax of waiting for 8 seconds and then set
"mIsListsDownloaded" to true. Could anyone help?
void DownloadLists ()
{
if (!mIsListsDownloaded)
{
// Loop -- Downloading entries for each list
foreach (ITritonList list in
TritonListManager.GetLists(true))
{
list.OpenEntries(new
ListDataReadyDelegate(OnEntriesDownloaded));
}
// Wrong in here, because the entries are not
downloaded at this time!!!
mIsListsDownloaded = true;
}
}
void OnEntriesDownloaded(IGridList list)
{
foreach (IGridEntry entry in list.Entries)
{
mEntries.Add(entry);
}
loggerCash.LogMessageBarMessage(ESeverity.Detail,
"Finished downloading entries on list " + list.Name.ToString());
}
The task is to download entries on each list for multiple lists and
then set "mIsListsDownloaded" to true. It's important that the action
"OnEntriesDownloaded" be completed for all of the lists before
"mIsListsDownloaded" is set to true.
I've found this a technical challenge -
The delegate method "OnEntriesDownloaded" takes time to complete.
Also, since "OnEntriesDownloaded" is called for each list and there
are multiple lists, it is called multiple times and it takes
significant amount of time (about 6 seconds, could take even longer
depending on how busy the system is) to complete.
Now the question is that when shall I set "mIsEntriesDownloaded" to
true? I want to wait for 8 seconds because by that time, all of the
entries should have been downloaded. However, there is no guarantee
because sometimes the system takes much longer.
I also don't know the C# syntax of waiting for 8 seconds and then set
"mIsListsDownloaded" to true. Could anyone help?