I want to create a Instance pool and use them again and again and not close them. But seems not work.
Anybody has suggestions? Thanks!
Part of the C# code:
Queue<Instance> zpInstanceQueue = CommonCode.ZPInstancePool(5);
int index=0;
string[] urls={"www.google.com","www.google.com","www.google.com","www.google.com","www.google.com"};
while (zpInstanceQueue.Count>0)
{
Instance zpInstance = zpInstanceQueue.Dequeue();
ZennoPoster.ShowInstance(zpInstance.Url, zpInstance.Port, zpInstance.Address);
// clear cookie
zpInstance.ClearCookie();
// go to lessons.zennolab.com
Tab tab = zpInstance.ActiveTab;
//if ((tab.IsVoid) || (tab.IsNull)) return -1;
if (tab.IsBusy) tab.WaitDownloading();
tab.Navigate(urls[index]);
if (tab.IsBusy) tab.WaitDownloading();
string text = tab.DomText;
string path = project.Directory+index+".txt";
FileSystem.FileAppendString(path, text, true);
}
---------------------------------------------------------------------------------------------
The following is OwnCode:
public class CommonCode
{
/// <summary>
/// Lock this object to mark part of code for single thread execution
/// </summary>
public static object SyncObject = new object();
// Insert your code here
public static Queue<Instance> ZPInstancePool(int capacity)
{
Queue<Instance> zpInstanceQueue = new Queue<Instance>();
for(int i =0;i< capacity; i++)
{
var url = "";
var port = 0;
var address = "";
// Gets parameters of instance
ZennoPoster.GetNewInstance(out url, out port, out address);
// Create new instance
var zpInstance = new Instance(url, port, address);
zpInstanceQueue.Enqueue(zpInstance);
}
return zpInstanceQueue;
}
}
Anybody has suggestions? Thanks!
Part of the C# code:
Queue<Instance> zpInstanceQueue = CommonCode.ZPInstancePool(5);
int index=0;
string[] urls={"www.google.com","www.google.com","www.google.com","www.google.com","www.google.com"};
while (zpInstanceQueue.Count>0)
{
Instance zpInstance = zpInstanceQueue.Dequeue();
ZennoPoster.ShowInstance(zpInstance.Url, zpInstance.Port, zpInstance.Address);
// clear cookie
zpInstance.ClearCookie();
// go to lessons.zennolab.com
Tab tab = zpInstance.ActiveTab;
//if ((tab.IsVoid) || (tab.IsNull)) return -1;
if (tab.IsBusy) tab.WaitDownloading();
tab.Navigate(urls[index]);
if (tab.IsBusy) tab.WaitDownloading();
string text = tab.DomText;
string path = project.Directory+index+".txt";
FileSystem.FileAppendString(path, text, true);
}
---------------------------------------------------------------------------------------------
The following is OwnCode:
public class CommonCode
{
/// <summary>
/// Lock this object to mark part of code for single thread execution
/// </summary>
public static object SyncObject = new object();
// Insert your code here
public static Queue<Instance> ZPInstancePool(int capacity)
{
Queue<Instance> zpInstanceQueue = new Queue<Instance>();
for(int i =0;i< capacity; i++)
{
var url = "";
var port = 0;
var address = "";
// Gets parameters of instance
ZennoPoster.GetNewInstance(out url, out port, out address);
// Create new instance
var zpInstance = new Instance(url, port, address);
zpInstanceQueue.Enqueue(zpInstance);
}
return zpInstanceQueue;
}
}