I want to use a instance pool in OwnCode, but it seems not work

StevenZ

Новичок
Регистрация
26.08.2019
Сообщения
3
Благодарностей
0
Баллы
1
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;
}
}
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 242
Благодарностей
5 848
Баллы
113
What does "not work" mean?
Do you get any error? Are instances not running?
What is happening when you execute your code?
 

StevenZ

Новичок
Регистрация
26.08.2019
Сообщения
3
Благодарностей
0
Баллы
1

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)