I have an Application in C#/Winforms that is basically used to run test for customers accounts in a specific order/setup. They are all tests run in browsers and so I built it so it would automate the process since there are about 10-12 tests that need to be ran everytime a customer account is pulled up.
Basically what happens is you input the account number then it runs the tests.
Here's a sample code.
public void startTestProcess()
{
if (!cancelTests)
{
testRunning = true;
var tabPage = createTabPage(banToRun, Convert.ToInt32(banToRun));
loadingBox.Visible = true;
mainTabControl.TabPages.Insert(0, tabPage);
mainTabControl.SelectedTab = mainTabControl.TabPages[0];
runTest(tabPage, banToRun);
loadingBox.Visible = false;
}
}
private void runTest(TabPage t, string ban)
{
if (!cancelTests && !cancelCurrentOnly)
{
var tC = createInitialTabControl();
t.Controls.Add(tC);
int[] theTests = profileInfo.getSetList;
for (int i = 0; i < theTests.Length; i++)
{
if (!cancelTests && !cancelCurrentOnly)
{
var newTab = createTabPage(urlStrings.getName(theTests[i]), theTests[i]);
tC.TabPages.Add(newTab);
var webBrowser = createBrowser(urlStrings.getUrl(theTests[i], ban));
newTab.Controls.Add(webBrowser);
if (theTests[i] != 0 && theTests[i] != 1 && theTests[i] != 6
&& theTests[i] != 11 && theTests[i] != 12)
{
if (!webBrowser.IsDisposed)
{
try
{
while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
}
catch
{
//Do Nothing
}
}
}
IntPtr pHandle = GetCurrentProcess();
SetProcessWorkingSetSize(pHandle, -1, -1);
}
}
}
if (cancelCurrentOnly)
{
cancelCurrentOnly = false;
}
banToRun = string.Empty;
testRunning = false;
}
So basically my question is, how can I optimize what I have in order to
A. Reduce lag/freezing - Note: Already implemented a way of forcing garbage collection after each test is run. B. Improve performance of the WebBrowser controls possibly? - Already tried some webbrowser alternatives like WebKit for C# Wrapper (does not work on all tests due to some ajax based coding i believe) C. Maybe implement multi-threaded operations. Not sure how i'd go about this without having cross-threaded exceptions thrown.
Thanks for your assistance. If you have any other questions feel free to ask.