Using asynchronous synchronous RSS in the ASP.net page

Source: Internet
Author: User

Sometimes we need to read the forum information in the Web page, in the traditional ASP when we are using JS or IFRAME, these two ways are not very convenient, and the search engine is not friendly. Now that we have. Net, we have another way.

Requirements: The forum needs to provide RSS support.

The code is as follows:

#region Task Class


//This is a task class that performs specific tasks


public class Rssasynctask


   {


private String _rsscontent;


private Asynctaskdelegate _dlgt;


private String Rssurl;


private bool _success;





public bool Issuccess


     {


Get


       {


return _success;


       }


     }





public Rssasynctask (string rssurl)


     {


This.rssurl = Rssurl;


     }





//Create delegate.


protected delegate void Asynctaskdelegate ();





Public String getrsscontent ()


     {


return _rsscontent;


     }


public void Dotheasynctask ()


     {


//introduce a artificial delay to simulate a delayed


//Asynchronous task. Make this greater than the


//AsyncTimeout property.


WebClient WC = new WebClient ();


Try


       {


_rsscontent = WC. Downloadstring (Rssurl);


_success = true;


       }


catch (Exception e)


       {


_rsscontent = e.message;


       }


finally


       {


WC. Dispose ();


       }


//thread.sleep (Timespan.fromseconds (5.0));


     }





//Define the method that'll get called to


//Start the asynchronous task.


public IAsyncResult Onbegin (object sender, EventArgs e,


AsyncCallback cb, Object Extradata)


     {


//_rsscontent = "beginning async task."





_dlgt = new Asynctaskdelegate (dotheasynctask);


IAsyncResult result = _dlgt. BeginInvoke (CB, Extradata);





return result;


     }





//Define The method that would get called when


//The asynchronous task is ended.


public void OnEnd (IAsyncResult ar)


     {


//_rsscontent = "Asynchronous task completed.";


_dlgt. EndInvoke (AR);


     }





Define the "method" that would get called if the task


//is not completed within the asynchronous timeout interval.


public void OnTimeOut (IAsyncResult ar)


     {


_rsscontent = "ansynchronous task failed to complete" +


"because it exceeded the asynctimeout parameter.";


     }


   }


#endregion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.