Open URL and refresh it continuously from C# app

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RuiT
    New Member
    • Dec 2009
    • 14

    Open URL and refresh it continuously from C# app

    How can I develop a C# application to open a page in a web browser, given the URL, and refresh it continuously (always the same URL)?
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Sounds like a DOS attack to me.

    Why would you want to do that?

    Comment

    • nispio
      New Member
      • Mar 2010
      • 3

      #3
      I am assuming by the fact that you say you want to refresh it continuously, you have no plans to USE the site, only to view it. If that is the case, you could just as easily make your own web browser with WinForms. The WebBrowser Control would allow you to display a page in it's own window. You would have total control over what page is shown and when it refreshes.

      Comment

      • RuiT
        New Member
        • Dec 2009
        • 14

        #4
        Yes, the page is displaying images only and I want to refresh it to change the image displayed. But this is a solution for the client side.

        Now I was wondering if there is any chance to do this on the server side, that is: user opens url in web browser and server changes the image to be displayed and refreshes the page automatically. Is this possible? How can I do this? Thanks.

        Comment

        • RuiT
          New Member
          • Dec 2009
          • 14

          #5
          I used the example posted here http://msdn.microsoft.com/en-us/library/3s8ys666.aspx to learn about the WebBrowser Control but I'm having trouble to refresh it continously.

          I tried to do this:

          while(true) //just to make it simple
          {
          webBrowser1.Ref resh();

          Thread.Sleep(20 0);
          }
          But nothing happened. How can I do this? Thanks!

          Comment

          • RuiT
            New Member
            • Dec 2009
            • 14

            #6
            Well I solve the question above using a thread.

            But I still want to develop an alternative solution that is server-side only. Summarizing: I want to build a web page on a server side that displays images, one at a time, once each one is saved on a folder, so that the client opens the URL only once and it is continuously refreshed so that he can watch the sequence of images as a video.

            Can somebody help me?

            Comment

            • RedSon
              Recognized Expert Expert
              • Jan 2007
              • 4980

              #7
              Wait, why don't you tell us what you are trying to accomplish. Don't tell me the implementation details, but what and why you are trying to do this.

              Continuously refreshing the browser is probably not what you want to do.

              Comment

              • RuiT
                New Member
                • Dec 2009
                • 14

                #8
                I'm trying to display a sequence of images on a web browser.

                What I have - Server: Images are saved on a folder.

                What I want - Client: Opens an Url and watch the sequence of images as a video

                Thanks for your time.

                Comment

                • tlhintoq
                  Recognized Expert Specialist
                  • Mar 2008
                  • 3532

                  #9
                  Code:
                  while(true) //just to make it simple
                  {
                  webBrowser1.Refresh();
                  
                  Thread.Sleep(200);
                  }
                  You're going to hammer the server every 200 ms - continuously? Obviously this isn't *your* server. Have a little respect for other people's sites.

                  You know many hosting providers have a limit of downloaded data. Its not an issue if you are running your own site. But if you are paying a company to host for you... once you hit that 20gig a month limit or whatever it either costs you a lot extra or they just shut you off.

                  Comment

                  • RedSon
                    Recognized Expert Expert
                    • Jan 2007
                    • 4980

                    #10
                    So you are talking about a slideshow? Doesn't it make more sense to use something like javascript or perhaps http://www.asp.net/AJAX/AjaxControlT...SlideShow.aspx?

                    People are going to insta block you if you spam their site like this trying to refresh 5 times a second.

                    Comment

                    • RuiT
                      New Member
                      • Dec 2009
                      • 14

                      #11
                      This is for an academic project - streaming a small video (as a sequence of images), the server is used for these kinds of researches and images are about 5 kB size, so it's ok.

                      This isn't the core of the project so I was looking for a simple and easy solution. I don't know anything about javascript or AJAX. Is there any other simpler solution for my problem that you can think of?

                      Thanks.

                      Comment

                      • RuiT
                        New Member
                        • Dec 2009
                        • 14

                        #12
                        I developed this application for the server:

                        Code:
                        namespace DisplayImages
                        {
                            public partial class _Default : System.Web.UI.Page
                            {
                        
                                string DirectoryPath = "C:\\Users\\VSProject\\Uploads\\";
                        
                                protected void Page_Load(object sender, EventArgs e)
                                {
                         
                                    FileSystemWatcher watcher = new FileSystemWatcher();
                        
                                    try
                                    {
                        
                                        watcher.Path = DirectoryPath;
                                        watcher.Created += new FileSystemEventHandler(watcher_Created);
                                        watcher.EnableRaisingEvents = true;
                        
                        
                                        Image image = Image.FromFile(DirectoryPath + "initial.jpg");
                                        MemoryStream ms = new MemoryStream();
                                        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                                        byte[] im = ms.ToArray();
                        
                                        Context.Response.ContentType = "Image/JPG";
                                        Context.Response.BinaryWrite(im);
                        
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                        
                                }
                        
                                void watcher_Created(object sender, FileSystemEventArgs e)
                                {
                                    Console.WriteLine("File Created: Name: " + e.Name);
                        
                                    try
                                    {
                                          //How to replace and display new image?
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }
                        
                            }
                        }
                        How ever I dont know how to replace and display the new image.

                        Somebody help?

                        Thanks.

                        Comment

                        • tlhintoq
                          Recognized Expert Specialist
                          • Mar 2008
                          • 3532

                          #13
                          Bytes has a policy regarding assisting students with their homework.

                          The short version is that the volunteers here can't help you with schoolwork.
                          A) We don't know what material you have and have not learned in class.
                          B) We don't know the guidelines you must follow.
                          C) In the long run giving you the answers actually short changes your education.

                          Hint 1: Try hitting Google with terms of your programming language and primary terms of what you want to do. For example "C# custom events" or "VB datagrid Excel". I've found this to be a very effective tool.
                          Hint 2: Your text book
                          Hint 3: Your instructor
                          Hint 4: Posting guidelines regarding homework assignments.

                          Comment

                          • RuiT
                            New Member
                            • Dec 2009
                            • 14

                            #14
                            I understand your policy but this is not my "homework", it's a research that I'm developing without any kind of instructor. There aren't guidelines or learned material, I just need to find a working solution. I've never worked with this before, please help.

                            Comment

                            • GaryTexmo
                              Recognized Expert Top Contributor
                              • Jul 2009
                              • 1501

                              #15
                              A question on syntax/usage of the .NET framework doesn't seem so bad to me :)

                              I played around with a web browser object a while back (***) and noticed that the refresh method had a couple options.

                              There's a completely option, that might work for you? Check out... http://msdn.microsoft.com/en-us/library/ts4tye44.aspx

                              That said, I kind of agree with the other posters here... there's gotta be a better solution than to refresh a web browser looking at an image. That solution would be for you to find out though ;)

                              *** Heads up, when I was playing around with this I was using google as the page I was going to and actually managed to get temp banned from Google! I know what you're thinking, but I wasn't doing anything untoward. I was just making a stripped down internet explorer to see how the functionality worked, but I guess Google doesn't like it. It detects it as an automated query. So I don't know if it's a bug with the web browser behaviour or if Google is too smart for it's own good, but I figured I'd point it out anyway.

                              Comment

                              Working...