Click here to Skip to main content
14,328,676 members
Rate this:
Please Sign up or sign in to vote.
See more:
Following code giving the error "Thread is a namespace used as type"
Printer p = new Printer();
ThreadStart ts = new ThreadStart(p.printSeries);
Thread th = new Thread(ts);

could you tell me please what is the problem??
Posted
Updated 28-Jan-15 0:07am
v2
Comments
Thomas Daniels 28-Jan-15 6:12am
   
At the top of your code file, in the namespace Name line, what's Name in your file?
TheRealSteveJudge 28-Jan-15 6:13am
   
Did you call the namespace of your programme "Thread"?
Sarita S 28-Jan-15 6:15am
   
My whole program code is as follows.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;


namespace Thread
{
class Program
{
static void Main(string[] args)
{
Printer p = new Printer();
ThreadStart ts = new ThreadStart(p.printSeries);
Thread th = new Thread(ts);

}

}
}
TheRealSteveJudge 28-Jan-15 6:17am
   
Please see solution 1.
Rate this:
Please Sign up or sign in to vote.

Solution 1

This is what I assumed!
Your namespace is called "Thread".
Please rename it to e.g. ThreadTest
   
Comments
Thomas Daniels 28-Jan-15 6:17am
   
+5
Sarita S 28-Jan-15 6:21am
   
Thanks its worked.
TheRealSteveJudge 28-Jan-15 6:25am
   
You're welcome!
TheRealSteveJudge 28-Jan-15 6:21am
   
Thank you!
Suvendu Shekhar Giri 28-Jan-15 6:42am
   
+5 for quick answer :)
TheRealSteveJudge 28-Jan-15 6:50am
   
Thank you!
BillWoodruff 28-Jan-15 10:51am
   
+5 smart detective work, there :)
TheRealSteveJudge 28-Jan-15 11:06am
   
Thank you!
Rate this:
Please Sign up or sign in to vote.

Solution 2

In your comment, there is this line:
namespace Thread

This means that you called the namespace of your program Thread. But at the Thread th = new Thread(ts); line, the compiler thinks that you target the namespace Thread, not the class Thread. You can change the name of your namespace to solve it.
   
Comments
TheRealSteveJudge 28-Jan-15 6:21am
   
We both had the same idea. 5*
Thomas Daniels 28-Jan-15 6:28am
   
Thank you!
Suvendu Shekhar Giri 28-Jan-15 6:41am
   
+5 for the explanation (Y)
Thomas Daniels 28-Jan-15 6:43am
   
Thank you!
Rate this:
Please Sign up or sign in to vote.

Solution 3

Simple. Change your namespace -

namespace Thread1
{
class Program
{
...


Thread is a system defined class. Change the namespace to something else.

Hope that helps :)
   
Comments
TheRealSteveJudge 28-Jan-15 6:22am
   
Also 5*.
Thomas Daniels 28-Jan-15 6:29am
   
+5
Suvendu Shekhar Giri 28-Jan-15 6:40am
   
Thanks :) we all have the same idea for this :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100