TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pfilips Mor
NA
8
542
Unable waiting for web page loading using WebBrowser control
Jan 28 2019 5:39 AM
I am writing a service with screenshots from the web pages of local sites.
I am using WebBrowser control to capture a webpage as an image.
Below is the code I am using:
namespace
MakeScreenShotURL
{
class
Program
{
private
static
Config config =
new
Config(System.Reflection.Assembly.GetExecutingAssembly().Location);
[STAThread]
static
void
Main()
{
int
width = 1700;
int
height = 1700;
string
username =
"userdata"
;
string
password =
"passworddata"
;
int
currentmonth = DateTime.Now.Month;
int
nextmonth = DateTime.Now.Month + 1;
int
year = DateTime.Now.Year;
screen(width, height, year, nextmonth, currentmonth, username, password);
}
static
void
screen(
int
width,
int
height,
int
year,
int
nextmonth,
int
currentmonth,
string
username,
string
password)
{
string
PlaceCode = config.GetAppSetting(
"place"
);
string
[] Places = PlaceCode.Split(
';'
);
//contains a list of sites for example: Berlin; Munich; Dresden
foreach
(
string
pl
in
Places)
{
using
(WebBrowser browser =
new
WebBrowser())
{
browser.Width = width;
browser.Height = height;
browser.ScrollBarsEnabled =
true
;
Uri uri =
new
Uri(
" http://localsite.php?y="
+ year +
"&m="
+ nextmonth +
"&p="
+ pl +
" "
);
string
additionalHeaderInfo =
"Authorization: Basic "
+ Convert.ToBase64String(Encoding.ASCII.GetBytes(username +
":"
+ password)) + System.Environment.NewLine;
browser.Navigate(uri,
null
,
null
, additionalHeaderInfo);
Wait(2);
//waiting for pages to load 2 seconds
using
(Graphics graphics = browser.CreateGraphics())
using
(Bitmap bitmap =
new
Bitmap(browser.Width, browser.Height, graphics))
{
Rectangle bounds =
new
Rectangle(0, 0, bitmap.Width, bitmap.Height);
browser.DrawToBitmap(bitmap, bounds);
bitmap.Save(
"C:/Users/user/image/screenshot"
+ pl +
".jpeg"
, ImageFormat.Jpeg);
}
Application.Run();
}
}
Application.Exit();
}
static
void
Wait(
int
number)
{
DateTime time = DateTime.Now;
do
{
Application.DoEvents();
}
while
(time.AddSeconds(number) > DateTime.Now);
}
}
}
The program creates a screenshot of the first element (Berlin) from the array of Places and saves it to disk.
But when selecting the second element from the array, the program hangs on the execution after the line:
Application.Run ();
Perhaps the program expects something but I cannot understand it.
Can someone help me to?
Reply
Answers (
2
)
Handling server exceptions with Breeze SaveChanges () Method
Attendance Management System