App exits on clicking search button

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
Im developing windows phone application for getting loading videos using xml. I have done a search option to filter videos, search works fine for first time. When I click on the first time searched video it gets played, but next time when I come back and
do a new search and press on search button Application exits. Please help me in fixing this. This is C# code I have used,
namespace Employees<br/>
{<br/>
public partial class MainPage : PhoneApplicationPage<br/>
{<br/>
// Constructor<br/>
public MainPage()<br/>
{<br/>
InitializeComponent();<br/>
<br/>
// is there network connection available<br/>
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())<br/>
{<br/>
MessageBox.Show("No network connection available!");<br/>
return;<br/>
}<br/>
// start loading XML-data<br/>
WebClient downloader = new WebClient();<br/>
Uri uri = new Uri("http://app.livehub.org/xml/funnyvideo.xml", UriKind.Absolute);<br/>
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(EmployeesDownloade);<br/>
downloader.DownloadStringAsync(uri);<br/>
}<br/>
<br/>
void EmployeesDownloade(object sender, DownloadStringCompletedEventArgs e)<br/>
{<br/>
if (e.Result == null || e.Error != null)<br/>
{<br/>
MessageBox.Show("There was an error downloading the XML-file!");<br/>
}<br/>
else<br/>
{<br/>
// Deserialize if download succeeds<br/>
XmlSerializer serializer = new XmlSerializer(typeof(Employees));<br/>
XDocument document = XDocument.Parse(e.Result);<br/>
// Employees employees = (Employees)serializer.Deserialize(document.CreateReader());<br/>
// employeesList.ItemsSource = employees.Collection;<br/>
Employees employees = (Employees)serializer.Deserialize(new StringReader(e.Result));<br/>
employeesList.ItemsSource = employees.Collection;<br/>
<br/>
}<br/>
}<br/>
<br/>
// selection in EmployeeList is changed<br/>
private void employeesList_SelectionChanged(object sender, SelectionChangedEventArgs e)<br/>
{<br/>
<br/>
<br/>
<br/>
var app = App.Current as App;<br/>
app.selectedEmployee = (Employee)employeesList.SelectedItem;<br/>
this.NavigationService.Navigate(new Uri("/EmployeePage.xaml", UriKind.Relative));<br/>
}<br/>
<br/>
private void Search_Click(object sender, EventArgs e)<br/>
{<br/>
MessageBox.Show("Will be Available in next version");<br/>
<br/>
//this.NavigationService.Navigate(new Uri("/Page.xaml", UriKind.Relative));<br/>
<br/>
<br/>
}<br/>
<br/>
private void More_Click(object sender, EventArgs e)<br/>
{<br/>
<br/>
<br/>
this.NavigationService.Navigate(new Uri("/browser.xaml", UriKind.Relative));<br/>
<br/>
}<br/>
<br/>
private void About_Click(object sender, EventArgs e)<br/>
{<br/>
this.NavigationService.Navigate(new Uri("/about.xaml", UriKind.Relative));<br/>
}<br/>
<br/>
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)<br/>
{<br/>
<br/>
e.Cancel = true;<br/>
MessageBoxResult result =<br/>
MessageBox.Show("Going to Exit",<br/>
"Message", MessageBoxButton.OKCancel);<br/>
if (result == MessageBoxResult.OK)<br/>
{<br/>
e.Cancel = false;<br/>
}<br/>
<br/>
if (result == MessageBoxResult.Cancel)<br/>
{<br/>
this.NavigationService.Navigate(new Uri("/about.xaml", UriKind.Relative));<br/>
}<br/>
<br/>
<br/>
}<br/>
<br/>
private void search_Click(object sender, RoutedEventArgs e)<br/>
{<br/>
// is there network connection available<br/>
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())<br/>
{<br/>
MessageBox.Show("No network connection available!");<br/>
return;<br/>
}<br/>
// start loading XML-data<br/>
WebClient downloader = new WebClient();<br/>
Uri uri = new Uri("http://app.livehub.org/xml/funnyvideo.xml", UriKind.Absolute);<br/>
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(EmployeesDownloaded);<br/>
downloader.DownloadStringAsync(uri);<br/>
}<br/>
<br/>
void EmployeesDownloaded(object sender, DownloadStringCompletedEventArgs e)<br/>
{<br/>
if (e.Result == null || e.Error != null)<br/>
{<br/>
MessageBox.Show("There was an error downloading the XML-file!");<br/>
}<br/>
else<br/>
{<br/>
<br/>
<br/>
// Deserialize if download succeeds<br/>
XmlSerializer serializer = new XmlSerializer(typeof(Employees));<br/>
XDocument document = XDocument.Parse(e.Result);<br/>
// Employees employees = (Employees)serializer.Deserialize(document.CreateReader());<br/>
// employeesList.ItemsSource = employees.Collection;<br/>
Employees employees = (Employees)serializer.Deserialize(new StringReader(e.Result));<br/>
employeesList.ItemsSource = employees.Collection.Where(emp => emp.title.ToLower().Contains(textBox1.Text.ToLower())).ToList();<br/>
<br/>
<br/>
}<br/>
}<br/>
<br/>
<br/>
}<br/>
}


View the full article
 

Similar threads

Back
Top