locked
Call another URL without opening a tab in web forms C# RRS feed

  • Question

  • User-1188570427 posted

    I need kick off a URL in the code that is running within a schedule task that runs every 3 minutes.

    I do not need to do a Response.Redirect() because I do not need to navigate to the tab because the website that is making the call needs to continue. 

    What is the best way to do this via web forms and C#?

    Thursday, November 1, 2018 12:49 AM

All replies

  • User-1188570427 posted

    I found the below code:

                            var request = (HttpWebRequest)WebRequest.Create(string.Format("{0}", urlToCall));
                            var response = (HttpWebResponse)request.GetResponse();

    But I do not care if I get a response or not. Is there a way I can just call the URL and not request a response back?

    Thursday, November 1, 2018 3:25 AM
  • User-893317190 posted

    Hi tvb2727,

    You could consider using ThreadPool to start a new thread to make your webrequest, because sending  request and receiving response is in another thread, it will not  disturb your  other operation in your main thread even though you receive the response.

    Below is  a sample to use thread pool in webform. After first step , the second step will run immediately and request will be sent in another thread.

     // the first step for example you write code 
    Console.Writeline("first")

    ThreadPool.QueueUserWorkItem( (obj) => { var req = (HttpWebRequest)WebRequest.Create(string.Format("{0}", "urltocall")); var response = (HttpWebResponse)req.GetResponse(); }, null);
    // the second step for example you write
    Console.Writeline("second")

    Best regards,

    Ackerly Xu

    Friday, November 2, 2018 7:09 AM