Suppose there is a ABCD.... sequence we want to print this sequence on Two threads. One thread printing in Upper case and another in Lower case without breaking the sequences or order.
Output should look like
A--thread1
a--thread2
B--thread1
b--thread2
C--thread1
c--thread2
Solution Code
using System;
using System.Threading;
class Program
{
static void Main()
{
Thread T1 = new Thread(new ThreadStart(Th1));
Thread T2 = new Thread(new ThreadStart(Th2));
T1.Start();
T2.Start();
}
static void Th1(){
string str ="ABCDEF" ;
foreach(char c in str){
Console.WriteLine(c.ToString().ToLower());
Thread.Sleep(1000);
}
}
static void Th2(){
string str ="ABCDEF" ;
foreach(char c in str){
Console.WriteLine(c);
Thread.Sleep(1000);
}
}
}
Output
A
a
B
b
C
c
Quick Notes for easy understanding. Chapters are on C#.Net,Linq,OOPS,Design Patterns,UML,Tools for development, Databases and many others. - Sid
Subscribe to:
Post Comments (Atom)
Code Formater
Paste Here Your Source Code | ||||||||||||||
Source Code Formatting Options | ||||||||||||||
|
||||||||||||||
Copy Formatted Source Code | ||||||||||||||
Preview Of Formatted Code |
No comments:
Post a Comment