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)?
16 12738
Sounds like a DOS attack to me.
Why would you want to do that?
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.
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.
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!
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?
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.
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.
- 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.
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.
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.
I developed this application for the server: -
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.
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.
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.
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.
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: -
public partial class _Default : System.Web.UI.Page
-
{
-
string DirectoryPath = "C:\\Users\\Desktop\\PhotoUpload\\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 display new image?
-
}
-
catch (Exception ex)
-
{
-
}
-
}
-
}
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |