A
amdrit
I have a need to create an instance of the webbrowser control in seperate
threads and display each on seperate forms in an MDI application. The
hosting site knows if the browser is in the same thread and will not isolate
the sessions for me. I can open seperate instances of IE or Netscape and
the site works fine, however it will not work fine in tabbed pages. So I
want to be able to have a singular application with mutliple browsers.
I think that I am creating the instance of my usercontrol in the wrong
manner but am unable to figure out what I need to change about it.
I am using C#'08
Thanks in advance and Happy Holidays
What I have done is:
project1 the dll
1. Create an interface to interact with the webbrowser control
public interface IMyBrowser
{
void StartUp();
}
2. Create a custom usercontrol that hosts the webbrowser control that
implements the interface
public class MyBrowser: UserControl, IMyBrowser
{
public void StartUp()
{
this.browser.Navigate(@MyWebsite);
}
}
Project2 the executable
1. Added a reference to the dll
2. Created a mdi form to host the mdi children
void MenuItemClick(...)
{
frmBrowser f = new frmBrowser();
f.mdiParent = this;
f.Show();
}
3. Created a mdi child form to host the browser control from the dll
public void frmBrowser()
{
InitializeComponent();
MyDll.MyBrowser instance =
(MyDll.MyBrowser)GetInstance<MyDll.IMyBrowser>();
if(instance != null)
{
this.controls.add(instance);
instance.dock = DockStyle.Fill;
instance.StartUp();
}
}
private object GetInstance<T>()
{
object instance = null;
string[] files =
Directory.GetFiles(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"*.dll");
foreach (string file in files)
{
Trace.WriteLine("Loading " + file);
try
{
Assembly assembly = Assembly.LoadFile(file);
foreach (Type type in assembly.GetTypes())
{
if (!type.IsClass || type.IsNotPublic) continue;
Type[] interfaces = type.GetInterfaces();
if (((IList)interfaces).Contains(typeof(T)))
{
instance = Activator.CreateInstance(type);
break;
}
}
}
catch (Exception ex)
{
//throw;
}
}
return instance;
}
threads and display each on seperate forms in an MDI application. The
hosting site knows if the browser is in the same thread and will not isolate
the sessions for me. I can open seperate instances of IE or Netscape and
the site works fine, however it will not work fine in tabbed pages. So I
want to be able to have a singular application with mutliple browsers.
I think that I am creating the instance of my usercontrol in the wrong
manner but am unable to figure out what I need to change about it.
I am using C#'08
Thanks in advance and Happy Holidays
What I have done is:
project1 the dll
1. Create an interface to interact with the webbrowser control
public interface IMyBrowser
{
void StartUp();
}
2. Create a custom usercontrol that hosts the webbrowser control that
implements the interface
public class MyBrowser: UserControl, IMyBrowser
{
public void StartUp()
{
this.browser.Navigate(@MyWebsite);
}
}
Project2 the executable
1. Added a reference to the dll
2. Created a mdi form to host the mdi children
void MenuItemClick(...)
{
frmBrowser f = new frmBrowser();
f.mdiParent = this;
f.Show();
}
3. Created a mdi child form to host the browser control from the dll
public void frmBrowser()
{
InitializeComponent();
MyDll.MyBrowser instance =
(MyDll.MyBrowser)GetInstance<MyDll.IMyBrowser>();
if(instance != null)
{
this.controls.add(instance);
instance.dock = DockStyle.Fill;
instance.StartUp();
}
}
private object GetInstance<T>()
{
object instance = null;
string[] files =
Directory.GetFiles(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"*.dll");
foreach (string file in files)
{
Trace.WriteLine("Loading " + file);
try
{
Assembly assembly = Assembly.LoadFile(file);
foreach (Type type in assembly.GetTypes())
{
if (!type.IsClass || type.IsNotPublic) continue;
Type[] interfaces = type.GetInterfaces();
if (((IList)interfaces).Contains(typeof(T)))
{
instance = Activator.CreateInstance(type);
break;
}
}
}
catch (Exception ex)
{
//throw;
}
}
return instance;
}