Sunday 26 December 2010

Force your Thread to start in Single-threaded apartment state

Use the below piece of code if you want to start your thread from main thread passing multiple parameters to that thread:

//by default this thread will start in MTA(Multi Apartment state)
string firstValue;
int secondValue;
bool thridValue;
//create an thread
Thread myAutomationThread;
// The delegate to call.
ThreadStart ts = new ThreadStart(delegate() { callMyFun(firstValue,secondValue,thirdValue); });
// The thread.
myAutomationThread = new Thread(ts);
// Run the thread.
myAutomationThread.Start();
----------
Now if you want to start the same thread in Single apartment state then just add the below line of code.
(We need to start the thread in STA because WATiN will run in STA mode only)

myAutomationThread.SetApartmentState(ApartmentState.STA);

The whole piece of code will look like this:

Thread myAutomationThread;
ThreadStart ts = new ThreadStart(delegate() { callMyFun(firstValue,secondValue,thirdValue); });
myAutomationThread = new Thread(ts);
myAutomationThread.SetApartmentState(ApartmentState.STA);
myAutomationThread.Start();

~Jawed

Download QC OTA API Reference Handbook /Documentation:

Download QC OTA API Reference Handbook /Documentation:

If you are looking for OTA (Open Test Architecture APU provided by hp QC then your search will end here.
I will explain you easy way to download API references details from QC.
a. Login to your QC
b. At Top most corner click on Help Link
c. From the pop-up window select Documentation Library as shown in below figure.



d. As soon as you will select above option a window will appear.
e. Select an option: HP QUALITY Center Open Test Architecture API reference Online
f. Click on online link next to the mentioned text
g. Save the references documentation at your drive.
h. Shown in below figure.


Hope this would be helpful !!

Thanks,

Md. Jawed

Log Visitors details using c#

Recently I have developed one application for the automation. It was web application.
I wanted to track the visitor visited or used my application and then store all the visitors information in "*.csv" file.
For that purpose I have used below code :

try
{
string strVisitorLogLocation=”C://VisitorsLog.csv” ;
string strIpAddress =Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (strIpAddress == null)
{
strIpAddress = Request.ServerVariables["REMOTE_ADDR"];
}

string hostName = Dns.GetHostByAddress(strIpAddress).HostName;
StreamWriter wrtr = new StreamWriter(strVisitorLogLocation, true);
wrtr.WriteLine(DateTime.Now.ToString() + "," + strIpAddress + "," + hostName + "," + Request.Url.ToString());
wrtr.Close();
}

catch (Exception ex)
{
//
}

you can use this snipet of the code to get the visitor details like hostname,ipaddress of visitor machine and which all pages he is visited on you application. Thanks!!
~jawed.