У меня есть динамическое решение, созданное с помощью VBScript, которое завершает работу объектов перед их повторным использованием. У моих пользователей обычно на рабочем столе открыты два или более сеанса IBM Personal Communications (PCOMM) для выполнения повседневных задач. Некоторые из этих сеансов регистрируются в собственных бизнес-приложениях, и их необходимо оставить в покое. Они также не могут использовать сеанс «А», поскольку это их производственный сеанс. Чтобы справиться с этим, я разработал следующую логику:
Set Connect_Manager = CreateObject("pcomm.autECLConnMgr")
Set autECLConnList = CreateObject("PCOMM.autECLConnList")
Set ObjEmulator = CreateObject("pcomm.auteclsession")
autECLConnList.Refresh
Num = autECLConnList.Count
PrevNum = Num
If Num = 0 Then
MsgBox "You must have at least two PCOMM sessions open to use this tool." & vbnewline & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "No Session Error"
SetEverythingToNothing
WScript.Echo "EXIT"
WScript.Quit
End If
strSession = autECLConnList(Num).Name
Connect_Manager.autECLConnList.Refresh
ObjEmulator.SetConnectionByName (strSession)
Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle
If InStr(Window_Title, "HOSTORS") 0 Or strSession = "A" Or InStr(Window_Title, "NDB") 0 Then
Set ObjEmulator = Nothing
Loop_Count = 1
Do
ResEmulator = "No"
PrevNum = PrevNum - 1
If PrevNum = 0 Then
MsgBox "You need to have more than one session open." & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "One Session Error"
SetEverythingToNothing
WScript.Echo "EXIT"
WScript.Quit
Else
strSession = autECLConnList(PrevNum).Name
If strSession = "A" Then
MsgBox "You cannot use your production (A) session." & vbnewline & "Please open another session." & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "Production Session Error"
SetEverythingToNothing
WScript.Echo "EXIT"
WScript.Quit
Exit Do
Else
Set ObjEmulator = CreateObject("pcomm.auteclsession")
Connect_Manager.autECLConnList.Refresh
ObjEmulator.SetConnectionByName (strSession)
Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle
If InStr(Window_Title, "NDB") 0 Or InStr(Window_Title, "HOSTORS") 0 Then
Set ObjEmulator = Nothing
Else
ResEmulator = "Yes"
End If
End If
End If
Loop_Count = Loop_Count + 1
If Loop_Count = 10 Then
MsgBox "Unable to connect to a session." & vbnewline & "Please make sure you have working sessions." & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "Production Session Error"
SetEverythingToNothing
WScript.Echo "EXIT"
WScript.Quit
Exit Do
End If
Loop Until ResEmulator = "Yes"
End If
Мой отдел переходит от VBScript к C#.NET. Я создал ОЧЕНЬ похожую версию кода VBScript.
AutConnList autECLConnList = new AutConnList();
AutConnMgr Connect_Manager = new AutConnMgr();
AutSess ObjEmulator = new AutSess();
autECLConnList.Refresh();
int Num = autECLConnList.Count;
int PrevNum = Num;
if (Num == 0)
{
MessageBox.Show("You must have at least two PCOMM sessions open to use this tool." + Environment.NewLine + Environment.NewLine + "Program is now terminating.", "No Session Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
return;
}
string strSession = autECLConnList[Num].Name;
autECLConnList.Refresh();
ObjEmulator.SetConnectionByName(strSession);
string Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle;
if (Window_Title.IndexOf("HOSTORS") == 0 || strSession == "A" || Window_Title.IndexOf("NDB") == 0)
{
ObjEmulator = null;
int Loop_Count = 1;
string ResEmulator = "No";
do
{
PrevNum -= 1;
if (PrevNum == 0)
{
MessageBox.Show("You need to have more than one session open." + Environment.NewLine + "Program is now terminating.", "One Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
return;
}
else
{
strSession = autECLConnList[PrevNum].Name;
if (strSession == "A")
{
MessageBox.Show("You cannot use your production (A) session." + Environment.NewLine + "Please open another session." + Environment.NewLine + "Program is now terminating.", "Production Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
return;
}
else
{
AutSess ObjEmulator = new AutSess();
autECLConnList.Refresh();
ObjEmulator.SetConnectionByName(strSession);
Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle;
if (Window_Title.IndexOf("HOSTORS") > 0 || Window_Title.IndexOf("NDB") > 0)
{
ObjEmulator = null;
}
else
{
ResEmulator = "Yes";
}
}
}
Loop_Count++;
if (Loop_Count == 10)
{
MessageBox.Show("Unable to connect to a session." + Environment.NewLine + "Please make sure you have working sessions." + Environment.NewLine + "Program is now terminating.", "Production Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
return;
}
} while (ResEmulator == "Yes");
}
Моя проблема заключается в том, что я получаю CS0136. Локальный параметр или параметр с именем ObjEmulator не может быть объявлен в этой области, поскольку это имя используется во включающей локальной области для определения локального или параметр, когда я пытаюсь повторно объявить AutSess ObjEmulator = new AutSess();. Я ищу аналогичный способ сохранить эту динамику, например, код VBScript. Поскольку ObjEmulator = null; не уничтожает объект полностью в C#.NET, как Set ObjEmulator = Nothing в VBScript, есть ли у кого-нибудь совет, как это можно сделать?
У меня есть динамическое решение, созданное с помощью VBScript, которое завершает работу объектов перед их повторным использованием. У моих пользователей обычно на рабочем столе открыты два или более сеанса IBM Personal Communications (PCOMM) для выполнения повседневных задач. Некоторые из этих сеансов регистрируются в собственных бизнес-приложениях, и их необходимо оставить в покое. Они также не могут использовать сеанс «А», поскольку это их производственный сеанс. Чтобы справиться с этим, я разработал следующую логику: [code]Set Connect_Manager = CreateObject("pcomm.autECLConnMgr") Set autECLConnList = CreateObject("PCOMM.autECLConnList") Set ObjEmulator = CreateObject("pcomm.auteclsession")
autECLConnList.Refresh Num = autECLConnList.Count PrevNum = Num
If Num = 0 Then MsgBox "You must have at least two PCOMM sessions open to use this tool." & vbnewline & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "No Session Error" SetEverythingToNothing WScript.Echo "EXIT" WScript.Quit End If
If InStr(Window_Title, "HOSTORS") 0 Or strSession = "A" Or InStr(Window_Title, "NDB") 0 Then Set ObjEmulator = Nothing Loop_Count = 1 Do ResEmulator = "No" PrevNum = PrevNum - 1 If PrevNum = 0 Then MsgBox "You need to have more than one session open." & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "One Session Error" SetEverythingToNothing WScript.Echo "EXIT" WScript.Quit Else strSession = autECLConnList(PrevNum).Name If strSession = "A" Then MsgBox "You cannot use your production (A) session." & vbnewline & "Please open another session." & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "Production Session Error" SetEverythingToNothing WScript.Echo "EXIT" WScript.Quit Exit Do Else Set ObjEmulator = CreateObject("pcomm.auteclsession") Connect_Manager.autECLConnList.Refresh ObjEmulator.SetConnectionByName (strSession) Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle If InStr(Window_Title, "NDB") 0 Or InStr(Window_Title, "HOSTORS") 0 Then Set ObjEmulator = Nothing Else ResEmulator = "Yes" End If End If End If Loop_Count = Loop_Count + 1 If Loop_Count = 10 Then MsgBox "Unable to connect to a session." & vbnewline & "Please make sure you have working sessions." & vbnewline & "Program is now terminating.", vbOKOnly + vbExclamation + vbSystemModal, "Production Session Error" SetEverythingToNothing WScript.Echo "EXIT" WScript.Quit Exit Do End If Loop Until ResEmulator = "Yes" End If [/code] Мой отдел переходит от VBScript к C#.NET. Я создал ОЧЕНЬ похожую версию кода VBScript. [code]AutConnList autECLConnList = new AutConnList(); AutConnMgr Connect_Manager = new AutConnMgr(); AutSess ObjEmulator = new AutSess();
autECLConnList.Refresh(); int Num = autECLConnList.Count; int PrevNum = Num;
if (Num == 0) { MessageBox.Show("You must have at least two PCOMM sessions open to use this tool." + Environment.NewLine + Environment.NewLine + "Program is now terminating.", "No Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); return; }
if (Window_Title.IndexOf("HOSTORS") == 0 || strSession == "A" || Window_Title.IndexOf("NDB") == 0) { ObjEmulator = null; int Loop_Count = 1; string ResEmulator = "No"; do { PrevNum -= 1; if (PrevNum == 0) { MessageBox.Show("You need to have more than one session open." + Environment.NewLine + "Program is now terminating.", "One Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); return; } else { strSession = autECLConnList[PrevNum].Name; if (strSession == "A") { MessageBox.Show("You cannot use your production (A) session." + Environment.NewLine + "Please open another session." + Environment.NewLine + "Program is now terminating.", "Production Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); return; } else { AutSess ObjEmulator = new AutSess(); autECLConnList.Refresh(); ObjEmulator.SetConnectionByName(strSession); Window_Title = ObjEmulator.autECLWinMetrics.WindowTitle; if (Window_Title.IndexOf("HOSTORS") > 0 || Window_Title.IndexOf("NDB") > 0) { ObjEmulator = null; } else { ResEmulator = "Yes"; } } } Loop_Count++; if (Loop_Count == 10) { MessageBox.Show("Unable to connect to a session." + Environment.NewLine + "Please make sure you have working sessions." + Environment.NewLine + "Program is now terminating.", "Production Session Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); return; } } while (ResEmulator == "Yes"); } [/code] Моя проблема заключается в том, что я получаю CS0136. Локальный параметр или параметр с именем ObjEmulator не может быть объявлен в этой области, поскольку это имя используется во включающей локальной области для определения локального или параметр, когда я пытаюсь повторно объявить AutSess ObjEmulator = new AutSess();. Я ищу аналогичный способ сохранить эту динамику, например, код VBScript. Поскольку ObjEmulator = null; не уничтожает объект полностью в C#.NET, как Set ObjEmulator = Nothing в VBScript, есть ли у кого-нибудь совет, как это можно сделать?