0

I would like to develop a "live" search control which displays the results in a popup menu when entering letters in a textbox. The data comes from a web service and a database on the LAN. My first thought was something like that (executing in a thread):

while (true)
{
    start:

    if (searchTermChanged)
    {
        clearData();
        showPopup();

        //get and add data from Webservice
        if (searchTermChanged) goto start
        //get and add data from database (query 1)
        if (searchTermChanged) goto start
        //get and add data from database (query 2)
    }
    Threading.sleep(10);

    goto start;
}

But somehow I do not like this solution! What do you think?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
roli09
  • 817
  • 1
  • 8
  • 20
  • 1
    So ... jQuery autocomplete then? – Adrian Wragg Nov 27 '14 at 21:27
  • 3
    Using `goto` in C# is a hanging offence in some countries. ;) – DeanOC Nov 27 '14 at 21:29
  • I think you could replace your `if ... goto start` with `continue` statement. – Im0rtality Nov 27 '14 at 21:32
  • I don't like "goto" too. The code above was meant as pseudo code. Sorry for that ;). I forgot to mention, that i develop a desktop application with winForm, so i cant use jQuery. – roli09 Nov 27 '14 at 21:36
  • Side note: using `Thread.Sleep()` even in pseudo-code sample welcomes down-votes or makes people ignore question... `await Task.Delay(10)` and async calls to get data (possibly combined with `Task.WhenAll(...)` ) would make your pseudo-code more modern and likely to attract readers. Also make sure to read on cross-thread calls - http://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c. – Alexei Levenkov Nov 27 '14 at 22:16
  • Thanks for your post alexei! Probably i can't use .net 4.5, because many of our clients haven't installed it. But i will check this again! – roli09 Nov 28 '14 at 05:26

0 Answers0