When and how to set a boolean variable to true?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Curious

    #1

    When and how to set a boolean variable to true?


    I have following code:

    void DownloadLists ()
    {

    if (!mIsListsDownl oaded)
    {

    // Loop -- Downloading entries for each list
    foreach (ITritonList list in
    TritonListManag er.GetLists(tru e))
    {
    list.OpenEntrie s(new
    ListDataReadyDe legate(OnEntrie sDownloaded));
    }

    // Wrong in here, because the entries are not
    downloaded at this time!!!
    mIsListsDownloa ded = true;
    }

    }


    void OnEntriesDownlo aded(IGridList list)
    {

    foreach (IGridEntry entry in list.Entries)
    {

    mEntries.Add(en try);
    }

    loggerCash.LogM essageBarMessag e(ESeverity.Det ail,
    "Finished downloading entries on list " + list.Name.ToStr ing());

    }

    The task is to download entries on each list for multiple lists and
    then set "mIsListsDownlo aded" to true. It's important that the action
    "OnEntriesDownl oaded" be completed for all of the lists before
    "mIsListsDownlo aded" is set to true.

    I've found this a technical challenge -

    The delegate method "OnEntriesDownl oaded" takes time to complete.
    Also, since "OnEntriesDownl oaded" 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 "mIsEntriesDown loaded" 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
    "mIsListsDownlo aded" to true. Could anyone help?
  • Mattias Sjögren

    #2
    Re: When and how to set a boolean variable to true?

    >Now the question is that when shall I set "mIsEntriesDown loaded" 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
    >"mIsListsDownl oaded" to true. Could anyone help?

    Can't you count the number of lists returned by
    TritonListManag er.GetLists(tru e) and then keep track of when
    OnEntriesDownlo aded has been called that number of times?


    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    Working...