This is how far i have done:
Start Searching for songs Async.
public void SubmitSearch()
{
AsyncCall ac = new AsyncCall(dc.AddToListBox);
AsyncCallback acb = new AsyncCallback(CallBackWorker);
ac.BeginInvoke(textBox1.Text, acb, null);
}
public void CallBackWorker(IAsyncResult iar)
{
MessageBox.Show("Finished");
}
this is a "painful place".
string url, name, length;
// this method is called by custom event, where EachSongInstance is instance of song - Url, Name, Length
void dc_OnListBox(object o, EachSongInstance e)
{
url = e.Url;
name = e.Name;
length = e.Length;
// this is how i call method, to add items on listBox.
this.Dispatcher.BeginInvoke(new Action(WorkWithUiThread), DispatcherPriority.Normal);
}
public void WorkWithUiThread()
{
// Instance of UserControl
ListBoxItem lbi = new ListBoxItem(url, name, length);
listBox1.Items.Add(lbi);
}
In result in listbox i get one song, many times. As far as i see, this is not the best practise to pass values from one method to other.
First of all, i would like to know, how can i call WorkWithUiThread() method with given parameters like WorkWithUiThread(string name, string url) using Dispatcher. And do there are any alternatives.

New Topic/Question
Reply



MultiQuote




|