using System;
using System.Threading ;
class Program {
public static void DoWork( object obj) {
Console.WriteLine ( "Child thread starts" ) ;
if ( obj is String)
Console.WriteLine ( obj as String) ;
else
throw new ArgumentException( "Parameter is not a string." , nameof( obj) ) ;
Console.WriteLine ( "Child thread goes to sleep" ) ;
Thread.Sleep ( 5000 ) ; // the thread is paused for 5000 milliseconds
Console.WriteLine ( "Child thread resumes and finishes" ) ;
}
static void Main( string[ ] args) {
ParameterizedThreadStart childJob = new ParameterizedThreadStart( DoWork) ;
Console.WriteLine ( "Main thread starts" ) ;
Thread childThread = new Thread( childJob) ;
childThread.Start ( "Message from Main" ) ;
Console.WriteLine ( "Main thread waiting" ) ;
childThread.Join ( ) ;
Console.WriteLine ( "Main thread finishes" ) ;
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwoKY2xhc3MgUHJvZ3JhbSB7CiAgcHVibGljIHN0YXRpYyB2b2lkIERvV29yayhvYmplY3Qgb2JqKSB7CiAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIkNoaWxkIHRocmVhZCBzdGFydHMiKTsKCiAgICAgaWYgKG9iaiBpcyBTdHJpbmcpCiAgICAgICBDb25zb2xlLldyaXRlTGluZShvYmogYXMgU3RyaW5nKTsKICAgICBlbHNlCiAgICAgICB0aHJvdyBuZXcgQXJndW1lbnRFeGNlcHRpb24oIlBhcmFtZXRlciBpcyBub3QgYSBzdHJpbmcuIiwgbmFtZW9mKG9iaikpOwogICAgIAogICAgIENvbnNvbGUuV3JpdGVMaW5lKCJDaGlsZCB0aHJlYWQgZ29lcyB0byBzbGVlcCIpOwogICAgIFRocmVhZC5TbGVlcCg1MDAwKTsgLy8gdGhlIHRocmVhZCBpcyBwYXVzZWQgZm9yIDUwMDAgbWlsbGlzZWNvbmRzCiAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIkNoaWxkIHRocmVhZCByZXN1bWVzIGFuZCBmaW5pc2hlcyIpOwogIH0KICAKICBzdGF0aWMgd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