Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 662513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:23:12+00:00 2026-05-13T23:23:12+00:00

In MS Exam 70-536 .Net Foundation , Chapter 7 Threading in Lesson 1 Creating

  • 0

In MS Exam 70-536 .Net Foundation, Chapter 7 “Threading” in Lesson 1 Creating Threads there is a text:

Be aware that because the WorkWithParameter method takes an object, Thread.Start
could be called with any object instead of the string it expects. Being careful in choosing
your starting method for a thread to deal with unknown types is crucial to good
threading code. Instead of blindly casting the method parameter into our string, it is
a better practice to test the type of the object, as shown in the following example:

' VB
Dim info As String = o as String
If info Is Nothing Then
    Throw InvalidProgramException("Parameter for thread must be a string")
End If
// C#
string info = o as string;
if (info == null)
{
    throw InvalidProgramException("Parameter for thread must be a string");
} 

So, I’ve tried this but exception is not handled properly (no console exception entry, program is terminated), what is wrong with my code (below)?

class Program
    {
        static void Main(string[] args)
        {
            Thread thread = new Thread(SomeWork);
            try
            {
                thread.Start(null);
                thread.Join();
            }
            catch (InvalidProgramException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {

                Console.ReadKey();
            }
        }

        private static void SomeWork(Object o)
        {
            String value = (String)o;
            if (value == null)
            {
                throw new InvalidProgramException("Parameter for "+
                    "thread must be a string");
            }
        }
    }

Thanks for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:23:12+00:00Added an answer on May 13, 2026 at 11:23 pm

    First start in VS in debug mode. Now to code, several issues:

        catch (InvalidProgramException ex)
        {
            Console.WriteLine(ex.Message);
        }
    

    will never be executed because exception is local to thread. If you throw exception in spawned thread other threads will not see it.

    throw new InvalidProgramException("Parameter for "+
                        "thread must be a string");
    

    this line causes unhandled exception, because in that thread no one caught it. unhandled exception fail entire app.

        String value = (String)o;
        if (value == null)
    

    o can be null which is valid value for String and your code will throw exceptions if o is not string. Did you meant:

        String value = o as String;
        if (value == null)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In MS Exam 70-536 .Net Foundation , Chapter 3 Searching, Modifying, and Encoding Text
Studying MS Exam 70-536 .Net Foundation I've got to Chapter 11 Application Security and
I remember seeing a question on my official MS 70-536 exam that talked about
I'm studying for the 70-536 exam and now I'm checking the lesson about converting
According to a mspress book (MCTS for Exam 70-536 .NET 2.0): You might have
I am thinking about taking the 70-536 exam, and there is all this stuff
My study guide (for 70-536 exam) says this twice in the text and encoding
I'm taking an exam tomorrow, and on that exam there is a bit about
I am reading the MCTS Self-Paced Training Kit (Exam 70-536): Microsoft .NET Framework—Application Development
I found this exam question that I have to tell how the beq instruction

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.