private bool SearchForWiki() { DelegateClass del = lyricWiki.getSong; IAsyncResult ar = del.BeginInvoke(this.artist, this.title, null, null); while (noOfTries < 9) { // If the user has aborted stop the search and return (false) if (Abort || lyricSearch.SearchHasEnded) { return(false); } else if (ar.AsyncWaitHandle.WaitOne(0, true)) { lyricsResult = del.EndInvoke(ar); string lyric = lyricsResult.lyrics; Encoding iso8859 = Encoding.GetEncoding("ISO-8859-1"); lyricsResult.lyrics = Encoding.UTF8.GetString(iso8859.GetBytes(lyricsResult.lyrics)); break; } else { // if we don't allow this pause of 2 sec the webservice behaves in a strange maneur Thread.Sleep(2000); } ++noOfTries; } if (lyricsResult != null && IsLyric(lyricsResult.lyrics)) { return(true); } else { noOfTries = 0; return(false); } }
private bool searchForWiki(string artist, string title) { DelegateClass del = lyricWiki.getSongResult; IAsyncResult ar = del.BeginInvoke(this.artist, this.title, null, null); while (noOfTries < 15) { // If the user has aborted stop the search and return (false) if (Abort) { return(false); } if (ar.AsyncWaitHandle.WaitOne(0, true)) { lyricsResult = del.EndInvoke(ar); break; } else { // if we don't allow this pause of 2 sec the webservice behaves in a strange maneur Thread.Sleep(2000); } ++noOfTries; } if (lyricsResult != null && isLyric(lyricsResult.lyrics)) { return(true); } else { noOfTries = 0; return(false); } }