473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Open URL and refresh it continuously from C# app

14
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)?
Mar 10 '10 #1
16 12738
RedSon
5,000 Expert 4TB
Sounds like a DOS attack to me.

Why would you want to do that?
Mar 10 '10 #2
nispio
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.
Mar 10 '10 #3
RuiT
14
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.
Mar 11 '10 #4
RuiT
14
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.Refresh();

Thread.Sleep(200);
}
But nothing happened. How can I do this? Thanks!
Mar 11 '10 #5
RuiT
14
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?
Mar 11 '10 #6
RedSon
5,000 Expert 4TB
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.
Mar 11 '10 #7
RuiT
14
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.
Mar 11 '10 #8
tlhintoq
3,525 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. while(true) //just to make it simple
  2. {
  3. webBrowser1.Refresh();
  4.  
  5. Thread.Sleep(200);
  6. }
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.
Mar 11 '10 #9
RedSon
5,000 Expert 4TB
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.
Mar 11 '10 #10
RuiT
14
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.
Mar 11 '10 #11
RuiT
14
I developed this application for the server:

Expand|Select|Wrap|Line Numbers
  1. namespace DisplayImages
  2. {
  3.     public partial class _Default : System.Web.UI.Page
  4.     {
  5.  
  6.         string DirectoryPath = "C:\\Users\\VSProject\\Uploads\\";
  7.  
  8.         protected void Page_Load(object sender, EventArgs e)
  9.         {
  10.  
  11.             FileSystemWatcher watcher = new FileSystemWatcher();
  12.  
  13.             try
  14.             {
  15.  
  16.                 watcher.Path = DirectoryPath;
  17.                 watcher.Created += new FileSystemEventHandler(watcher_Created);
  18.                 watcher.EnableRaisingEvents = true;
  19.  
  20.  
  21.                 Image image = Image.FromFile(DirectoryPath + "initial.jpg");
  22.                 MemoryStream ms = new MemoryStream();
  23.                 image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  24.                 byte[] im = ms.ToArray();
  25.  
  26.                 Context.Response.ContentType = "Image/JPG";
  27.                 Context.Response.BinaryWrite(im);
  28.  
  29.             }
  30.             catch (Exception ex)
  31.             {
  32.             }
  33.  
  34.         }
  35.  
  36.         void watcher_Created(object sender, FileSystemEventArgs e)
  37.         {
  38.             Console.WriteLine("File Created: Name: " + e.Name);
  39.  
  40.             try
  41.             {
  42.                   //How to replace and display new image?
  43.             }
  44.             catch (Exception ex)
  45.             {
  46.             }
  47.         }
  48.  
  49.     }
  50. }
  51.  
How ever I dont know how to replace and display the new image.

Somebody help?

Thanks.
Mar 11 '10 #12
tlhintoq
3,525 Expert 2GB
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.
Mar 11 '10 #13
RuiT
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.
Mar 11 '10 #14
GaryTexmo
1,501 Expert 1GB
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.
Mar 11 '10 #15
RuiT
14
I know that refreshing continuously a web browser is not a good solution! It works, sure, but I know it's not great.

That's why I'm trying to come up with a better solution, as I wrote before: A server-side only solution which replaces images and refreshes only when a new image has arrive to the folder. That's what I'm trying to develop now. I'm using FileSystemWatcher to monitor the folder, as the following code snippet shows:

Expand|Select|Wrap|Line Numbers
  1. public partial class _Default : System.Web.UI.Page
  2. {
  3.     string DirectoryPath = "C:\\Users\\Desktop\\PhotoUpload\\Uploads\\";
  4.  
  5.     protected void Page_Load(object sender, EventArgs e)
  6.     {
  7.         FileSystemWatcher watcher = new FileSystemWatcher();
  8.  
  9.         try
  10.         {
  11.             watcher.Path = DirectoryPath;
  12.             watcher.Created += new FileSystemEventHandler(watcher_Created);
  13.             watcher.EnableRaisingEvents = true;
  14.  
  15.             Image image = Image.FromFile(DirectoryPath + "initial.jpg");
  16.             MemoryStream ms = new MemoryStream();
  17.             image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  18.             byte[] im = ms.ToArray();
  19.  
  20.             Context.Response.ContentType = "Image/JPG";
  21.             Context.Response.BinaryWrite(im);
  22.         }
  23.         catch (Exception ex)
  24.         {
  25.         }
  26.     }
  27.  
  28.     void watcher_Created(object sender, FileSystemEventArgs e)
  29.     {
  30.         Console.WriteLine("File Created: Name: " + e.Name);
  31.  
  32.         try
  33.         {
  34.           //How to display new image?  
  35.         }
  36.         catch (Exception ex)
  37.         {
  38.         }
  39.     }
  40. }
Can you give me some hints in how to replace the previous image for the new one? How can I make it refresh so the client watches the sequence of images? Here can I get a tutorial, examples or some kind of help?
I think that what I want to do is pretty simple, the problem is that I've never worked in web development before.

Please help.

PS - Hope you understand by now that I'm not a regular student in a hurry to do my homework. And please note that this is not the core of my project, hence I'm not that concerned about developing the optimal solution and to learn everything about web development.
Mar 11 '10 #16
Have you tried using Firefox and an Add-on? URL Flipper comes to mind. https://addons.mozilla.org/en-US/fir...d=5&sort=&lup=
Mar 17 '10 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: yanivmad | last post by:
hi I like to ask if there any option to control the html files?!? I have some HTML files at my web site that use one "Help.htm" file for all the pages {I use the "window.open(.... " option at...
2
by: John | last post by:
Hi. When I use VB.NET projects, Visual Studio refreshes the display when I correct errors. (i.e. removes the blue and red lines under syntax errors etc.) But when I use C# projects, the display...
2
by: Raed Sawalha | last post by:
Hello: I have 2 windows application 1st one is periodically writing specific data to XML file , the 2nd application has a dialog with DataGrid , the datagrid filled with information in the XML...
2
by: Robert Mileski | last post by:
I've made some program in Visual Basic 2005 that works with changing files and folders. After I've finished it, the main problem is to refresh the Windows OS. I mean the same thing as when we press...
6
by: scott | last post by:
I guess this is a simple one but I can't seem to get it to work. I want to refresh an open form "onClose" of another. I have a Close button on a form which has User Details on it. If I update...
2
by: Robert | last post by:
I am trying to give the user dynamic search capabilities to select almost any record in the database from criteria they select. Everything seems to work except when I open the display form to...
25
by: bubbles | last post by:
Using Access 2003 front-end, with SQL Server 2005 backend. I need to make the front-end application automatically refresh the linked SQL Server tables. New tables will be added dynamically in...
4
by: Scott | last post by:
I'm trying to get access to open, refresh and then close an excel spreadsheet for me. Below is the code I'm using to open and close Excel, I just can't get it to refresh my data linked back to my...
11
by: PW | last post by:
One of my ASP's was working fine for a long time. Now it has started constantly refreshing itself. Everytime I run it I just get the first part of the page, then it refreshes itself, the rest of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.