Click here to Skip to main content
15,892,298 members
Home / Discussions / C#
   

C#

 
QuestionHow to merg two datatable Pin
linqabc18-Apr-10 4:12
linqabc18-Apr-10 4:12 
AnswerRe: How to merg two datatable Pin
Abhinav S18-Apr-10 4:28
Abhinav S18-Apr-10 4:28 
QuestionVB.Net solution to C# Pin
mehrdadc4818-Apr-10 3:24
mehrdadc4818-Apr-10 3:24 
AnswerRe: VB.Net solution to C# Pin
Abhinav S18-Apr-10 3:42
Abhinav S18-Apr-10 3:42 
AnswerRe: VB.Net solution to C# Pin
Brij18-Apr-10 6:24
mentorBrij18-Apr-10 6:24 
AnswerRe: VB.Net solution to C# Pin
Dave Doknjas18-Apr-10 10:18
Dave Doknjas18-Apr-10 10:18 
QuestionOptimising part of a code thats bulky Pin
malcomhfc18-Apr-10 1:21
malcomhfc18-Apr-10 1:21 
AnswerRe: Optimising part of a code thats bulky Pin
Gideon Engelberth18-Apr-10 16:34
Gideon Engelberth18-Apr-10 16:34 
Well, lets see what's in common between your three methods. Everything is the same except for the address you read and which ItemsControl you are filling. If you combined those two things into a separate class, you could simplify the form code.

The class would look something like this:
C#
public class FeedReader
{
    FeedReader(string address, ItemsControl target)
    {
        _address = address;
        _target = target;
    }
    
    private string _address;
    private ItemsControl _target;
    
    public void LoadFeed()
    {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(_address));
        request.BeginGetResponse(new AsyncCallback(ResponseHandler), request);
    }
    
    private void ResponseHandler(IAsyncResult asyncResult)
    {
        HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);

        if (response.StatusCode == HttpStatusCode.OK)
        {
            XmlReader reader = XmlReader.Create(response.GetResponseStream());
            SyndicationFeed newFeed = SyndicationFeed.Load(reader);
            _target.Dispatcher.BeginInvoke(delegate
            {
                _target.ItemsSource = newFeed.Items;
            });

        }
    }
}


And the calling code could then be:
C#
public NewsFeed()
{
    InitializeComponent();
    SupportedOrientations = SupportedPageOrientation.Portrait;
    Loaded += new RoutedEventHandler(MainPage_Loaded);

    PageTransitionList.Completed += new EventHandler(PageTransitionList_Completed);

    // Set the data context of the listbox control to the sample data
    //DataContext = new MainViewModel();

    //////////////////////////////
    ///// Here's the changes /////
    //////////////////////////////
    FeedReader bbc = new FeedReader("http://www.pchelpforum.com/external.php", ListBbc);
    FeedReader dailyMail = new FeedReader("http://www.dailymail.co.uk/home/index.rss", ListDailyMail);
    FeedReader guardian = new FeedReader("http://www.guardian.co.uk/tv-and-radio/rss", ListGuardian);

    //just call this, no other routines needed for updating.
    //all updates are taken care of by the FeedReader class methods.
    bbc.LoadFeed();
    dailyMail.LoadFeed();
    guardian.LoadFeed();
    
    //////////////////////////////
    //////////////////////////////
    //////////////////////////////
}

GeneralRe: Optimising part of a code thats bulky Pin
malcomhfc21-Apr-10 10:42
malcomhfc21-Apr-10 10:42 
QuestionprogressBar with percents display [modified] Pin
igalep13218-Apr-10 0:55
igalep13218-Apr-10 0:55 
AnswerRe: progressBar with percents display [modified] Pin
Luc Pattyn18-Apr-10 1:11
sitebuilderLuc Pattyn18-Apr-10 1:11 
GeneralRe: progressBar with percents display [modified] Pin
igalep13218-Apr-10 1:21
igalep13218-Apr-10 1:21 
GeneralRe: progressBar with percents display Pin
Som Shekhar18-Apr-10 3:58
Som Shekhar18-Apr-10 3:58 
GeneralRe: progressBar with percents display Pin
igalep13218-Apr-10 4:00
igalep13218-Apr-10 4:00 
GeneralRe: progressBar with percents display Pin
Som Shekhar18-Apr-10 4:04
Som Shekhar18-Apr-10 4:04 
GeneralRe: progressBar with percents display Pin
igalep13218-Apr-10 4:08
igalep13218-Apr-10 4:08 
GeneralRe: progressBar with percents display Pin
Som Shekhar18-Apr-10 4:13
Som Shekhar18-Apr-10 4:13 
AnswerRe: progressBar with percents display Pin
igalep13218-Apr-10 11:48
igalep13218-Apr-10 11:48 
QuestionMessage Removed Pin
17-Apr-10 21:19
Nadia Monalisa17-Apr-10 21:19 
AnswerRe: Do I need to uninstall Visual Studio 2008 in order to install VS 2010 Professional ? Pin
OriginalGriff17-Apr-10 21:30
mveOriginalGriff17-Apr-10 21:30 
GeneralRe: Do I need to uninstall Visual Studio 2008 in order to install VS 2010 Professional ? Pin
Nadia Monalisa17-Apr-10 21:40
Nadia Monalisa17-Apr-10 21:40 
QuestionWill my .NET 2.0 Control work in .NET 4.0 application ? Pin
Nadia Monalisa17-Apr-10 21:14
Nadia Monalisa17-Apr-10 21:14 
AnswerRe: Will my .NET 2.0 Control work in .NET 4.0 application ? Pin
Abhinav S17-Apr-10 23:19
Abhinav S17-Apr-10 23:19 
QuestionSelect Area Pin
Frozzeg17-Apr-10 10:44
Frozzeg17-Apr-10 10:44 
AnswerRe: Select Area Pin
Luc Pattyn17-Apr-10 11:42
sitebuilderLuc Pattyn17-Apr-10 11:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.