|
Hello,
I created a C# console application (without GUI) that scrapes information from webpages. This application runs everyday on a unattended computer with Win2003 SP3, including latest security patches and up to date virusscanner, using a scheduled task. It uses the C# System.Windows.Forms.WebBrowser class to navigate the pages.
The application runs fine for weeks but all of a sudden the following error occurs
Win32Exception details: HRESULT=-2147467259 ecode=87 inner=
Failure... System.ComponentModel.Win32Exception: The parameter is incorrect
at System.Windows.Forms.NativeWindow.WindowClass.RegisterClass()
at System.Windows.Forms.NativeWindow.WindowClass.Create(String className, Int32 classStyle)
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Application.MarshalingControl..ctor()
at System.Windows.Forms.Application.ThreadContext.get_MarshalingControl()
at System.Windows.Forms.WindowsFormsSynchronizationContext..ctor()
at System.Windows.Forms.WindowsFormsSynchronizationContext.InstallIfNeeded()
at System.Windows.Forms.Control..ctor(Boolean autoInstallSyncContext)
at System.Windows.Forms.WebBrowserBase..ctor(String clsidString)
at System.Windows.Forms.WebBrowser..ctor()
at MyNamespace.Scraper.Scrape()
An important code snippet:
public class Scraper
{
private WebBrowser browser;
public void Scrape()
{
using (browser = new WebBrowser())
{
NaviateToPage(browser);
ScrapeContent(browser);
}
}
}
The application is started every hour. It will run OK for days, until the exception occurs. When the exception occurs it keeps occuring. BUT when a user logs into the system and opens a browser and closes it again. The system runs fine for a couple of days again, until the exception shows up again (from that point on it will continue to fail again until somebody logs on... etc).
The exception is "The parameter is incorrect", but because I don't provide any parameters I don't have a clue which parameter might be incorrect and why.
I examed internet explorer settings on the machine and even scanned the registry for strange settings, but couldn't find anything that could point me in the right direction.
I also looked at the running processes. I examined which processes are running when the problem occurs and when the system is running fine, but there are not differences.
I am a kind of desparately looking for good ideas or background info that can point me in the right direction.
Thanx!
Paul
|
|
|
|
|
Hi,
the WebBrowser documentation states:
The WebBrowser control is resource-intensive. Be sure to call the Dispose method when you are finished using the control to ensure that all resources are released in a timely fashion. You must call the Dispose method on the same thread that attached the events, which should always be the message or user-interface (UI) thread.
And:
The WebBrowser class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.
Your code uses the using statement, so Dispose is called.
The other requirements need to be verified.
The exception is an inner exception; ecode=87 means invalid parameter,
and HRESULT=-2147467259 corresponds to hex 80004005 which inside good old winerror.h
is the value for the symbols ERROR_REC_NON_EXISTENT as well as E_FAIL. so that
seems not to help us.
One guess is each new WebBrowser creates a new class name, and somehow these class
names suddenly are not valid any more. Suggestion: count and log each new WebBrowser
and try to recognize a pattern in the failures.
Another idea is something runs out, e.g. disk space for temporary internet files;
you might try to see if something like that occurs, and can be remedied without
launching IE, just to see if your app resumes normal operation.
Hope this helps.
|
|
|
|
|
Luc, thanx for the input.
Both the dispose (through the using statement) and the single thread apartment (STA) were already in place. Your comments show that I was on the right track adding those two.
I already checked the processes and active webbrowsers and system resources, but nothing can be seen there.
This weekend the server was rebooted, which killed some processes. Of course with the reboot the errors disappeared. Because I did not reboot the system since I implemented the STA and dispose actions, some problem processes might have been left in memory. Possibly this reboot might have solved this and could lead to a long-term solution.
I can only be sure if this works after a week or so. Then I'll report the final conclusion. Again, thanx for the input.
Paul
|
|
|
|
|
Hi All,
The solution seems to work. The Using Statement caused the Dispose function of the Webbrowser to be called. This solution was already implemented, but the problem remained.
Because the old version of the software, where the Dispose was not called, was running before, old "resource claims" probably were still active.
A reboot of the system seems to have solved the problem by releasing those claimed resources. The system is running fine now for a month now, while before to the problem occured every 4 or 5 days at least.
Luc, thanx for the help!
Paul
|
|
|
|
|
Hi Paul, you're welcome.
|
|
|
|
|
Afternoon All
I was wondering if anyone knew of any articles relating to GIS programming specifically for C#?
I would like to know more about plotting longitude and lattitude coordinates onto a vector diagram but am unsure how to go about rendering these vector diagrams in the first instance. Basically I suppose I am looking to build a GIS Vector viewer using C# but am at a loss as to where I should begin.
Any help greatfully appreciated
All the best
Col
|
|
|
|
|
|
Eh yeah already tried that but was hoping someone may have something a bit more specific
|
|
|
|
|
Well you'll have to be a bit more specific yourself. Firstly do you know C#, and secondly do you know anything about GIS?
If we can establish how much you know then perhaps we can help you more.
Also if you can be more specific on what you are trying to accomplish then that'd be helpful too, i.e. is this a just for fun project or does it have an ultimate goal at the end?
|
|
|
|
|
Hi Ed
I have a pretty good understanding of C#. I understand GIS to a degree but what I suppose I am not clear on is displaying the information. By that I mean if I have a dxf file, I would know how to read the file, plot the points and join these up. But the thing I cannot get my head around is if I had a vector diagram (dxf format again, say a shot of the Grand Canyon), obviously this is Geo-positioned, but if I was to plot a point on that diagram, how would I do that? How would I set my viewer up to handle well 'space' I guess. I could plot a point, but would it be displayed accurately on the diagram?
I know we have various coordinate systems, but I am unsure how to code this into an actual viewer.
This project is something I have wanted to do for a long time. Basically I want to take a vector image of a town and load on top of that coordinates from a GPS session plotting the route taken. It is purely for, ahem, 'fun' although it is currently driving me a bit potty. If I could just get to grips with how I present images within a coordinate system, I think I would be in a slightly better position.
I realise this is a bit fragmented and aplogise for this. If you have any further questions, please let me know and I will do my best to answer these clearly.
Many thanks
Colin
|
|
|
|
|
Well I've done a lot of work with Ordnance Survey Grid References[^] but these deal only with Cartesian coordinates, i.e. an X and a Y. The first major question to ask yourself is are you going to deal with 2D data or 3D. I realise that coordinate systems aren't that straight forward because of the skews etc.
But basically what you would want is if you can load your image of the town with a known coordinate, e.g. the top-left corner of the town-hall is so many degress/minutes/seconds north and west then when you read in your GIS data you can use this as your origin for calculations.
cols2910 wrote: but I am unsure how to code this into an actual viewer.
So if I've understood you correctly you can read the vector files but don't know how to display them?
If you don't know how to draw them then you have 3 possibilities (well actually two), you can use GDI+ with C#, Managed DirectX or WPF. What I meant by having 2 is that WPF uses DirectX internally and even is easily capable of 2D or 3D data very simply as well as all the graphics transformations. However if you're not on Vista or XP SP2 then you're stuck on that front.
For example I've got portions of Great Britain in the OS format 1:25000 (1km = 4cm), these are stored as pictures 200 pixels by 200 pixels. With this information I know that the name of the picture refers to the Grid Reference in the bottom left corner of the picture. 200 pixels then equals 1km.
So if I wanted to plot the point SN512876 I would draw the pictures stored in file SN510870.png (this is the point 51km west and 87km north of the origin for the grid code SN, see linked article if you want to know more). That's the base image loaded (the town in your case), I then have to plot the more accurate point.
So for the X coordinate (in pixels) from the bottom-left of the picture:
x = (512 - xOffset) * ScalingFactor
y = (876 - yOffset) * ScalingFactor Where the xOffset = 510 and yOffset = 870. The scaling factor in this instance is 20 because 200 pixels = 1km so 0.1 of a km = 20 pixels.
So in summary the most important things to get are a known coordinate on the image and the scaling of the image, for example you need to know how wide / tall the image is so that you can scale things accordingly.
|
|
|
|
|
Excellent Ed
I see where you are coming from. I had in my mind something along those lines, but your explanation has cemented a few ideas I had.
I have dealt with Rasters before, but mostly in the likes of MapInfo or SmallWorld but on the basis of what you said I think I could now develop a viewer for that. I would assume Vector wouldshare the same principles
Many hanks
Colin
|
|
|
|
|
|
How can i do to integrate The Visual Studio 2003 for using a CVSRepo?
|
|
|
|
|
In my application, there is a datagrid control and there are several columns on it. You know that datagrid control applies sorting data but I want to sort as multiple columns.
For example, two columns are date and username. Firstly datagrid sort by date and after sort by username. Sorting priority of date greater than username.
Date UserName
12.03.07 Mehmet
12.01.06 John
24.05.08 Michael
24.05.08 Anna
12.03.07 Becham
Sorting by only date
Date UserName
12.01.06 John
12.03.07 Mehmet
12.03.07 Becham
24.05.08 Michael
24.05.08 Anna
Sorting by firstly date and after, by UserName
Date UserName
12.01.06 John
12.03.07 Becham
12.03.07 Mehmet
24.05.08 Anna
24.05.08 Michael
Thanks for your helps.
|
|
|
|
|
I think you can sort by the following codes.
// Only UserName
MyDateGrid.Source = MyDataView;
MyDataGrid.Sort = "UserName";
MyDataGrid.DataBind();
// First UserName than date:
MyDateGrid.Source = MyDataView;
MyDataGrid.Sort = "UserName, theDate";
MyDataGrid.DataBind();
// First date than UserName:
MyDateGrid.Source = MyDataView;
MyDataGrid.Sort = "theDate, UserName";
MyDataGrid.DataBind();
You also need a property that knows what the last sorthing
method was.
private string lastSortCommand = "";
<br />
if(lastSortCommand == "UserName" && currentSortCommand == "theDate")<br />
{<br />
MyDateGrid.Source = MyDataView;<br />
MyDataGrid.Sort = "theDate, UserName";<br />
MyDataGrid.DataBind();<br />
}<br />
else if(lastSortCommand == "theDate" && currentSortCommand == "UserName")<br />
{<br />
MyDateGrid.Source = MyDataView;<br />
MyDataGrid.Sort = "UserName, theDate";<br />
MyDataGrid.DataBind();<br />
}<br />
else<br />
{<br />
MyDateGrid.Source = MyDataView;<br />
MyDataGrid.Sort = currentSortCommand;<br />
MyDataGrid.DataBind();<br />
}<br />
lastSortCommand = currentSortCommand;<br />
Haven't tryed it out, but I'll think i works.
|
|
|
|
|
hi all, i am gonna deploy my windows project using clickonce feature of VS2005
for that i am trying to create an instance to application.deployment
but i left with result, error------ InvalidDeploymentException{"Application identity is not set."}
its also giving click once application is not istalled
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
how can we check whether the click once application is installed or not...Programatically
Thnx in advance,
prashanth
|
|
|
|
|
Try this [^]forum set of questions / responses.
|
|
|
|
|
How to register COM object when created in VS2005 Express ?
I've tried checking Register for COM interop in Project Properties->Build , i've tried Regasm.exe utility and still when I try Add Refrence -> COM , that object is not there...
|
|
|
|
|
Now when I checked warnings, there is a Warning: "C:\Documents and Settings\stefanz\My Documents\Visual Studio 2005\Projects\Test45_COM\bin\Release\Test45_COM.dll" does not contain any types that can be registered for COM Interop. I've done everything according to Creating simple COM objects using interop
|
|
|
|
|
Hey Guys,
I've got a asp.net web application. Its a simple application which connects to a SQL Server 2005 Mobile database. I would now like to write a windows application which will wrap this asp.net web application and allow it to be executed normally.
I was thinking of using the in-build webdev server somehow in the windows application. Then, add the webdev.exe to the setup project of the windows app.
Can this be done? If so, how would I go about doing this? I have been searching on google, and will continue to do so. I haven't found a info on this topic.
Thanks.
|
|
|
|
|
Hi!
I am facing problem when inserting large amount of data in XML file. I am using C# 2005. I am using XML file as a replacement of database table. My application stores as many as 100000 or more records in XML file, but it takes too much time in inserting/retrieving these records (almost 1-2 minutes).
I have made such insertion before but at that time structure of each node of XML was very simple with no child nodes, it took 1-2 seconds to insert 100000 records at that time. But now structure of each node is different. Each node contains 5-6 child nodes..
Previously i used MS Access for this purpose but faced same problem so switched to XML, now the data insertion/retrieval time is reduced almost 5 times but my problem is not solved, i want to insert/retrieve 100000 records in maximum 15 seconds.
Please tell me why this problem is occuring, can XML be used as alternative of database? If not then how can i obtain required results...? is there any thing else available for this, other than database and XML...
I put this question in XML/XSD board but i was adviced to consult C# group..
Thanks in advance...
Regards,
Affan Ahmad Toor
|
|
|
|
|
Affan Toor wrote: can XML be used as alternative of database?
No. XML should be used as a data transport mechanism between disparate systems. It should not be used as a database.
Affan Toor wrote: If not then how can i obtain required results...?
Perhaps you database schema was not optimised for what you want to do.
|
|
|
|
|
The amount of records you are trying to process seems a bit excessive for a xml file. I would rather look into something like mysql or sql 2005 express. Both are excelent and should have no trouble in handling a lot of data.
|
|
|
|
|
Although this an old article it may enlighten you http://www.codeproject.com/soap/xmltiming.asp[^]
XML can be used as a small datastore. Note the SMALL, yours is to large for this to be a viable option, as you have found out. I would suggest using SQL Server Express or SQL Server COmpact Edition.
only two letters away from being an asset
|
|
|
|