26.02.2015 Views

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

DOT NET Interview Questions - DotNetSpider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As<br />

System.EventArgs) Handles MyBase.Load<br />

Dim pthread1 As New Thread(AddressOf Thread1)<br />

Dim pthread2 As New Thread(AddressOf Thread2)<br />

pthread1.Start()<br />

pthread2.Start()<br />

End Sub<br />

Public Sub Thread1()<br />

Dim pintcount As Integer<br />

Dim pstr As String<br />

pstr = “This is first thread”<br />

Do Until pintcount > 5<br />

lstThreadDisplay.Items.Add(pstr)<br />

pintcount = pintcount + 1<br />

Loop<br />

End Sub<br />

Public Sub Thread2()<br />

Dim pintcount As Integer<br />

Dim pstr As String<br />

pstr = “This is second thread”<br />

Do Until pintcount > 5<br />

lstThreadDisplay.Items.Add(pstr)<br />

pintcount = pintcount + 1<br />

Loop<br />

End Sub<br />

Above is a sample code which shows simple sample code for threading..Above sample<br />

code can be found in “Threading” folder in CD provided.Above sample has two methods<br />

“Thread1()” and “Thread2()” which are started in multi-threaded mode in Form load<br />

event of the sample.<br />

Note :- If you run the sample you will see that sometimes the first thread runs first and<br />

then the second thread.This happens because of thread priorities .The first thread is run<br />

with highest priority.<br />

(A)How can we change priority and what the levels of priority are<br />

provided by .<strong>NET</strong> ?<br />

Thread Priority can be changed by using Threadname.Priority = ThreadPriority.Highest.In<br />

the sample provided look out for code where the second thread is ran with a high priority.<br />

53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!