Open web browser control multiple times by using background worker, using
list with Thread in C#
I want to do in my project that user select a text file which have some
number of website address. when all the website address from the text file
bounded with listview control, then there is a button for browsing this
links into web browser control which I have created at another form. all
this work done by BACKGROUND WORKER control at 1st Form. I calling the
backgroundWorker1.RunWorkerAsync(_WebList); where WebList is List which
contains all the links address which is showing at Listview in the 1st
Form. Now at the DoWorkEventArgs event of the backgroundworker1 I am
browsing all the links but I am getting error. private void
backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { List _WebList
= new List(); _WebList = (List)e.Argument; Thread t = new Thread(() => {
for (int i = 0; i < _WebList.Count; i++) { BrowserIntegration obj = new
BrowserIntegration(_WebList[i].ToString()); obj.Show(); if
(!ShowBrowserchck.Checked) { obj.Hide(); } } }); t.ApartmentState =
ApartmentState.STA; t.Start(); t.Join(); } Error: Here I can't cancel the
Async function and all the form are open too much fast and then disposed
if I am doing another coding with DoWorkEventArgs event of
backgroundworker then I got other error. private void
backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { List _WebList
= new List(); _WebList = (List)e.Argument; for (int i = 0; i <
_WebList.Count; i++) { BrowserIntegration obj = new
BrowserIntegration(_WebList[i].ToString()); obj.Show(); if
(!ShowBrowserchck.Checked) { obj.Hide(); } } } Here I got error with web
browser control : ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2'
cannot be instantiated because the current thread is not in a
single-threaded apartment. anyone can please help me regarding this
topic.....
No comments:
Post a Comment