I am getting values from a database, and trying to insert them into Internet Explorers history, using the UrlHistoryWrapper class. When I set the for
conditions to something in the thousands, I will get this error, however, when I set the for condition to less than 100, it will run fine. I have checked the memory usage, and it should cause no problems. How can I make this code able to run, if chrome.URLs and firefox.URLs have thousands of values?
This is my code:
UrlHistoryWrapperClass urlHistory;
UrlHistoryWrapperClass.STATURLEnumerator enumerator;
List<STATURL> list = new List<STATURL>();
urlHistory = new UrlHistoryWrapperClass();
enumerator = urlHistory.GetEnumerator();
bool display = false;
chrome.GetHistory(display);
for (int i = 0; i < chrome.URLs.Count; i++ )
{
URL url = chrome.URLs[i];
urlHistory.AddHistoryEntry(url.url, url.title, ADDURL_FLAG.ADDURL_ADDTOHISTORYANDCACHE);
}
Firefox firefox = new Firefox();
firefox.GetHistory(display:false);
foreach (URL url in firefox.URLs)
{
MessageBox.Show(url.url);
urlHistory.AddHistoryEntry(url.url, url.title, ADDURL_FLAG.ADDURL_ADDTOHISTORYANDCACHE);
}
And this is my error:
***** Exception Text ******* System.Runtime.InteropServices.COMException (0x80070008): Not enough storage is available to process this command. (Exception from HRESULT: 0x80070008) at UrlHistoryLibrary.IUrlHistoryStg2.AddUrl(String pocsUrl, String pocsTitle, ADDURL_FLAG dwFlags) at UrlHistoryLibrary.UrlHistoryWrapperClass.AddHistoryEntry(String pocsUrl, String pocsTitle, ADDURL_FLAG dwFlags) at Namespace.IE.SyncIE() in C:\Users\Chris\documents\visual studio 2010\Projects\TestURLGUI4\TestURLGUI4\URLHistory.cs:line 270 at Namespace.Program.SyncAll() in C:\Users\Chris\documents\visual studio 2010\Projects\TestURLGUI4\TestURLGUI4\URLHistory.cs:line 152 at TestURLGUI2.Form1.button11_Click(Object sender, EventArgs e) in C:\Users\Chris\documents\visual studio 2010\Projects\TestURLGUI4\TestURLGUI4\Form1.cs:line 247 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Edit:
Here is my new code:
for (var i = 0; i < firefox.URLs.Count; i++ )
{
URL url = firefox.URLs[i];
urlHistory.AddHistoryEntry(url.url, url.title, ADDURL_FLAG.ADDURL_ADDTOHISTORYANDCACHE);
Thread.Sleep(3);
form.label1.Text = i + "/" + firefox.URLs.Count;
// MessageBox.Show(url.url);
Application.DoEvents();
}
Now, with this code, I can go up to 8447 without getting this error, but then it gets thrown.
I had someone else try to do this, and this is what he said:
Just tried your code and and it seems that there is a limit on the number of the url records that can be added. I did the following steps.
- In Internet Explorer, Clear the history of websites I've visited.
- I tried your code.
- Got a COMException (0x80070008): Not enough storage is available to process this command. The exception is thrown at record number 41021 for me (Windows 7, 64bit).
- I tried your code again, and Got a very same exception. This time, No record have be added. To add the url records again. I have to clear the history of websites in Internet Explorer. I could not find a way to fix the problem.
For anyone who needs to know, the source code for the URLhistoryWrapper can be found on this CodeProject project.
Here is the solution I found to work. U need to run the
foreach (URL url in firefox.URLs)
{
MessageBox.Show(url.url);
urlHistory.AddHistoryEntry(url.url, url.title, ADDURL_FLAG.ADDURL_ADDTOHISTORYANDCACHE);
}
and the chrome ones, etc, in another thread. Like this:
Thread testthread = new Thread(SynceFirefoxToIE);
testthread.Name = "FirefoxToIESynceThread";
testthread.Start();
}
public void SynceFirefoxToIE()
{
foreach (URL url in firefox.URLs)
{
urlHistory.AddHistoryEntry(url.url, url.title, ADDURL_FLAG.ADDURL_ADDTOHISTORYANDCACHE);
}
}
User contributions licensed under CC BY-SA 3.0